How to sum all column values in multi-dimensional array?

后端 未结 20 2525
花落未央
花落未央 2020-11-22 00:57

How can I add all the columnar values by associative key? Note that key sets are dynamic.

Input array:

Arr         


        
20条回答
  •  天涯浪人
    2020-11-22 01:19

    $newarr=array();
    foreach($arrs as $value)
    {
      foreach($value as $key=>$secondValue)
       {
           if(!isset($newarr[$key]))
            {
               $newarr[$key]=0;
            }
           $newarr[$key]+=$secondValue;
       }
    }
    

提交回复
热议问题