Mega Code Archive

 
Categories / Php / Data Type
 

Displaying a multidimensional array

<?php $objects=array('A' =>    array('Shape'    => 'Cylinder',                                       'Color'    => 'Red',                                       'Material' => 'Metal'),                'B' =>    array('Shape'    => 'Rectangle',                                       'Color'    => 'White',                                       'Material' => 'Paper'),                'C' =>       array('Shape'    => 'Sphere',                                       'Color'    => 'Red',                                       'Material' => 'Fruit'),                'D' =>      array('Shape'    => 'Sphere',                                       'Color'    => 'Orange',                                       'Material' => 'Fruit'),                'E' =>  array('Shape'    => 'Rectangle',                                       'Color'    => 'Yellow',                                       'Material' => 'Paper')); echo $objects['Soda can']['Shape']; foreach ($objects as $obj_key => $obj) {     echo "$obj_key:<br>";     while (list ($key,$value)=each ($obj))     {         echo "$key = $value ";     }     echo "<br />"; } ?>