Accessing multidimensional array elements : Multidimensional Array « Data Structure « PHP





Accessing multidimensional array elements

 
<?
$meals = array('breakfast' => array('A','C'),
               'lunch'     => array('B', 'E'),
               'snack'     => array('C','F'));

$lunches = array( array('Chicken','Eggplant','Rice'),
                  array('Eggplant','Tofu'));

$flavors = array('Japanese' => array('hot' => '1',
                                     'salty' => '2'),
                 'Chinese'  => array('hot' => '3',
                                     'pepper-salty' => '4'));

print $meals['lunch'][1];            
print $meals['snack'][0];            
print $lunches[0][0];                
print $lunches[2][1];                
print $flavors['Japanese']['salty']  
print $flavors['Chinese']['hot'];    
?>
  
  










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.Creating Multidimensional Arrays
6.Creating a Multidimensional Array
7.Sorting Multidimensional Arrays
8.Multidimensional array element value interpolation
9.Displaying Multidimensional Arrays
10.Displaying a multidimensional array
11.Find the Maximum Value in a Multidimensional Array
12.Generating fixed-width field data records without
13.Manipulating multidimensional arrays