如何在PHP中计算多维数组的值
我试图创建一个表来计算存储在多维数组中的数据值,并以表格式显示结果 我不知道如何计算存储在数组的数组中的值三级数组的值 我可以使用该函数计算多维数组值中的值吗?希望有人能教我,谢谢如何在PHP中计算多维数组的值,php,arrays,function,multidimensional-array,Php,Arrays,Function,Multidimensional Array,我试图创建一个表来计算存储在多维数组中的数据值,并以表格式显示结果 我不知道如何计算存储在数组的数组中的值三级数组的值 我可以使用该函数计算多维数组值中的值吗?希望有人能教我,谢谢 <?php $itemList = array ("book"=>array("ID"=>"14567", "name"=>array("History"=>array("American"=>12,"Europe"=>2), "SF
<?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;
?>
回声计数$category
这里您得到了类别的总计数创建另一个foreach循环,其中每个迭代加+1
foreach($itemList['book']['name'] as $key => $value)
{
foreach ($itemList['book']['name'][$key] as $key1 => $value1) {
$category[] = $key1;
$value2[] = $value1;
}
}