You want to associate mutiple elements with a single key.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"> <head> <title>PHP</title> <meta Name="Author" Content="Hann So"> </head> <body> <p> <?php echo "<p><b>This is a multidimensional array.</b></p>"; $fruits = array('red' => array('Apples', 'Stawberries'), 'yellow' => array('Bananas', 'Pineapple'), 'green' => array('Grapes', 'Kiwis') ); echo "<p><b>Using print_r().</b></p>"; print_r($fruits); echo "<p><b>Using foreach.</b></p>"; foreach ($fruits as $color=>$color_fruits) { // $color_fruits is an array foreach($color_fruits as $fruit) { echo "$fruit are colored $color. <br />"; } } ?> </p> </body> </html> |