时间:2021-07-01 10:21:17 帮助过:16人阅读
$ar = array( array( 'a' => 2, 'b' => 6), array( 'a' => 5, 'b' => 7),);$t = array();foreach($ar as $r) { foreach($r as $k=>$v) @$t[$k] += $v;}$ar[] = $t;print_r($ar);
Array( [0] => Array ( [a] => 2 [b] => 6 ) [1] => Array ( [a] => 5 [b] => 7 ) [2] => Array ( [a] => 7 [b] => 13 ))
感谢版大~~~
或
$ar = array( array( 'a' => 2, 'b' => 6), array( 'a' => 5, 'b' => 7),);$t = call_user_func_array('array_map', array_merge(array(null),$ar));$t = array_map('array_sum', $t);$t = array_combine(array_keys($ar[0]), $t);$ar[] = $t;print_r($ar);