PHPでforeach文サンプル:多次元配列の出力

<?php
$food = array(
  "vegetable" => array(
      "carrot"=> "にんじん",
      "tomato" => "トマト",
      "onion" => "たまねぎ"
  ), // カンマ , で区切る
  "fruit" => array(
      "apple" => "りんご",
      "orange" => "オレンジ",
      "grape" => "ぶどう"
  )
); // 文終了のセミコロン ;
 
foreach( $food as $key1 => $val1 ){
  echo "--".$key1. "--<br />\n";
 
  foreach( $val1 as $key2 => $val2 ){
    echo $key2. ":" .$val2."<br />\n";
  }
}
?>


ネタ元