$ary = [ "fruits" => ["apple", "banana"], "animal" => ["monkey", "cat"] ]; $ary["fruits"][] = "kui"; foreach($ary as $key => $value){ echo "-" . $key . "<br>"; foreach($value as $k => $v){ echo $v . " "; } echo "<br>"; }
– 二次元配列の中に配列を入れたい
$ary = [ "A商事" => [ "注文1" => ["商品1", "500円", "3個", "1500円"], "注文2" => ["商品2", "600円", "2個", "1200円"] ], "B商事" => [ "注文3" => ["商品3", "700円", "1個", "700円"] ] ]; $ary["B商事"]["注文4"] = ["商品4", "200円", "10個", "2000円"]; echo "<pre>"; var_dump($ary); echo "</pre>";
これを呼び出したい
foreach($ary as $key => $value){ echo "-". $key . "<br>"; foreach($value as $k => $v){ echo $k. ":"; foreach($v as $n => $data){ echo $data . " "; } } echo "<br>"; }
OK、 これに$keyごとの小計を加えたい