我需要获得每个指定月份数组中所有数值的总和。理想情况下,它将返回以下格式。
四月
总计=22
三月
total="sum"
Array
(
[April] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] =>
[4] => 3
[5] =>
[6] => 2
[7] => 6
[8] => 3
[9] => 2
)
[March] => Array
(
[0] => 3.19198
[1] => 2.52219
[2] => 3.40053
[3] => 2.42639
[4] => 3.92301
[5] => 3.23758
[6] => 3.22457
[7] => 2.62855
)
使用array_map()
:在每个子阵列上应用array_sum()
$result = array_map('array_sum', $data);
输出:
Array
(
[April] => 22
[March] => 24.5548
)
演示