PHP Multidimensional Arrays

PHP Multidemensional Arrays

Multidemensional arrays are arrays of arrays. Multidemensional arrays will be indexed, but the arrays they index can be indexed or associative arrays. The example below consists of two associative arrays. You access the first array with the 0 index; such as $my_array[0]. To access an associative array value you need to choose the key. For example, $my_array[0][Email] selects the email value of the first array.

echo "<br/><br/>";
$my_array = array(array( 'Firstname' => 'Joe',
                  'Lastname'  => 'Rogers',
                  'Email'     =>''),
                  array('Firstname' => 'James',
                  'Lastname'  => 'Rogers',
                  'Email'     =>''));


echo $my_array[0][Firstname]." ".$my_array[0][Lastname];

echo "<br/><br/>";

echo $my_array[1][Firstname]." ".$my_array[1][Lastname];