Displaying a multidimensional array : Multidimensional Array « Data Structure « PHP






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 />";
}
?>
  
  








Related examples in the same category

1.Reference element in multidimensional Arrays
2.Defining a Multidimensional Array
3.Looping Through a Multidimensional Array
4.Displaying a Multidimensional Array using For each
5.Accessing multidimensional array elements
6.Creating Multidimensional Arrays
7.Creating a Multidimensional Array
8.Sorting Multidimensional Arrays
9.Multidimensional array element value interpolation
10.Displaying Multidimensional Arrays
11.Find the Maximum Value in a Multidimensional Array
12.Generating fixed-width field data records without
13.Manipulating multidimensional arrays