php自带的函数:array_sum,推荐使用,但是有时没法满足项目过程中的使用,
我在php.net上找到了一个函数:
here is a function that can sum values like these :
$tab = array(
0 => array ("val1" => 2,"val2" => 5)
1 => array ("val1" => 6,"val2" => 10)
"toto" => array ("val1" => 15,"val2" => 50)
);
sum_subarrays_by_key( $tab, "val1" );
the function will sum all values with "val1" key in tab subarrays.
function s...