【发布时间】:2014-10-03 18:23:43
【问题描述】:
我尝试创建一个表格来计算存储在多维数组值中的数据并按表格格式显示结果。
我不知道如何计算存储在数组数组中的值(第三级数组的值。
我可以使用该函数来计算多维数组值中的值吗?希望有人能教教我,谢谢。
<?php
$itemList = array
("book"=>array("ID"=>"14567",
"name"=>array("History"=>array("American"=>12,"Europe"=>2), "SF"=>array("Space"=>32), "Chinese"=>array("kungFu"=>10))),
"stationary"=>array("ID"=>"24547", "name"=>array("HB"=>array("ABC"=>123, "MC"=>161,"GCD"=>26)))
);
$item = "<table border=1>";
$item .= "<td>item count(s)</td>";
foreach($itemList as $key => $value){
$item .= "<tr>";
$item .= "<td align=center>" .
/*count the categories of the items(e.g. American,Europe,Space,Kungfu show
the result: "4")*/
. "</td>";
$item .= "</tr>";
}
$item .= "</table>";
echo $item;
?>
【问题讨论】:
-
创建另一个 foreach 循环,在其中为每次迭代添加 +1
标签: php arrays function multidimensional-array