php - How can I add these arrays? -


how can addition of total_qty_ordered of arrays?

this can number of arrays

       array ( [0] => array ( [total_qty_ordered] => 1.0000 [1] => ) [1] => array      ( [total_qty_ordered] => 1.0000 [1] => ) [2] => array ( [total_qty_ordered] => 1.0000  [1] =>      ) [3] => array ( [total_qty_ordered] => 1.0000 [1] => ) [4] => array (  [total_qty_ordered] =>      1.0000 [1] => ) [5] => array ( [total_qty_ordered] => 1.0000 [1] => ) [6] => array (      [total_qty_ordered] => 1.0000 [1] => ) [7] => array ( [total_qty_ordered] => 1.0000 [1]  => )      [8] => array ( [total_qty_ordered] => 1.0000 [1] => ) [9] => array (  [total_qty_ordered] =>      2.0000 [1] => ) [10] => array ( [total_qty_ordered] => 1.0000 [1] => ) [11] => array (  [total_qty_ordered] => 1.0000 [1] => ) ) 

$sum = array_sum(array_map(function($item){   return $item['total_qty_ordered']; }, $array)); 

but if array structure (2nd value empty), can do:

$sum = array_sum(call_user_func_array('array_merge',             array_map('array_values', $array))); 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -