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
Post a Comment