I have a java app sending me an array via an XMLRPC in this format
Array ( [0] => Array ( [VMNAME] => 102208b-Joomla15-1 [ISEXPIRED] => 0 [DAYSTOEXPIRE] => 25 ) [1] => Array ( [VMNAME] => 102208b-Joomla15-2 [ISEXPIRED] => 1 [DAYSTOEXPIRE] => -6 ) [2] => Array ( [VMNAME] => 102208b-Joomla15-3 [ISEXPIRED] => 1 [DAYSTOEXPIRE] => -6 ) [3] => Array ( [VMNAME] => 102208b-Joomla15-4 [ISEXPIRED] => 1 [DAYSTOEXPIRE] => -6 ) [4] => Array ( [VMNAME] => 102208b-Joomla15-100 [ISEXPIRED] => 1 [DAYSTOEXPIRE] => -4 ) [5] => Array ( [VMNAME] => 102208b-Joomla15-101 [ISEXPIRED] => 0 [DAYSTOEXPIRE] => 20 ) [6] => Array ( [VMNAME] => 102208b-Joomla15-85 [ISEXPIRED] => 1 [DAYSTOEXPIRE] => -2 ) )
I need to drop the data into a select drop down this format:
<option value="VMNAME"> VMNAME - Expires in DAYSTOEXPIRE days </option>
The array has been set in the session as 'vmlist' and I have tried using the array_pluck function to grab the data in the format. My current code is:
function array_pluck($key, $array)
{
if (is_array($key) || !is_array($array)) return array();
$funct = create_function('$e', 'return is_array($e) && array_key_exists("'.$key.'",$e) ? $e["'. $key .'"] : null;');
return array_map($funct, $array);
}
$vmlisting = array_pluck("VMNAME", $vmlist);
$expirationdate = array_pluck("DAYSTOEXPIRE", $vmlist);
$ext_eval .= 'Select a virtual machine to extend : ';
$ext_eval .= '<select name="vmname" id="vmname" size="1">'."\r\n";
foreach ($vmlisting as $key => $value ) {
foreach ($expirationdate as $key => $expdatevalue ) {
$ext_eval .= "\t".'<option value="'.$value.'">' . $value.' - Expires in '. $expdatevalue .' days </option>'."\r\n";
}
}
$ext_eval .= '</select>';
However it outputs:
<select name="vmname" id="vmname" size="1">
<option value="102208b-Joomla15-1">102208b-Joomla15-1 - Expires in 375 days </option>
<option value="102208b-Joomla15-1">102208b-Joomla15-1 - Expires in 60 days </option>
<option value="102208b-Joomla15-1">102208b-Joomla15-1 - Expires in -1 days </option>
<option value="102208b-Joomla15-2">102208b-Joomla15-2 - Expires in 375 days </option>
<option value="102208b-Joomla15-2">102208b-Joomla15-2 - Expires in 60 days </option>
<option value="102208b-Joomla15-2">102208b-Joomla15-2 - Expires in -1 days </option>
<option value="102208b-Joomla15-3">102208b-Joomla15-3 - Expires in 375 days </option>
<option value="102208b-Joomla15-3">102208b-Joomla15-3 - Expires in 60 days </option>
<option value="102208b-Joomla15-3">102208b-Joomla15-3 - Expires in -1 days </option>
</select>
Why is it duplicating rather than matching up the correct keys? ??
I hope this makes since....