How do I display the individual values from this array?
for instance: X = 8.6; Y = 43; F = more stuff?
$MEGA['Stuff'] = [
8.6,
43,
'more stuff'
];
How do I display the individual values from this array?
for instance: X = 8.6; Y = 43; F = more stuff?
$MEGA['Stuff'] = [
8.6,
43,
'more stuff'
];
Adding to Object Manipulator answer, above, in case you cannot manipulate the original array, you could use the array_combine
function to set the keys to the array, thus reducing the need of iterating over it twice.
$keys = ["X", "Y", "F"];
$MEGA["Stuff"] = array_combine($keys, $MEGA["Stuff"]);
Now the $MEGA["Stuff"]
array is in the form, Object Manipulator has it, and you can manipulate it at your liking
You could make it an associative array with key-value pair.
$MEGA['Stuff'] = [
'X' => 8.6,
'Y' => 43,
'F' => 'more stuff'
];
foreach ($MEGA['Stuff'] as $k => $v) {
echo $k . ' : '. $v;
echo '<br/>';
}
suppose k,y and f is fix therefor use can use following code. you have 3 characters k,y,f right
arrays count is 3
now you can make code like this
$char=array('k','y','f');
get count of $MEGA['Stuff'];
$count=count($MEGA['Stuff']);
Now we are using for loop.
for($i=0;$i<$count;$i++)
{
echo $char[$i].' = '.$MEGA['Stuff'][$i];echo '<br/>';
}
You can use this code for display value from array.
You can just use echo to display the data:
echo $MEGA['stuff'][0])
echo $MEGA['stuff'][1])
echo $MEGA['stuff'][2])