Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中计算多维数组的值_Php_Arrays_Function_Multidimensional Array - Fatal编程技术网

如何在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;
    }

 }