我在多维数组中有这些值:
array
0 =>
array
0 => float 0.11521247274056
1 => float 0.081839214900844
2 => float 0.084168850912272
3 => float 0.18520831868443
1 =>
array
0 => float 0.92169978192452
1 => float 0.65471371920675
2 => float 0.84168850912272
3 => float 0.43215274359699
2 =>
array
0 => float 0.23042494548113
1 => float 0.13094274384135
2 => float 0.16833770182454
3 => float 0.18520831868443
3 =>
array
0 => float 0.038404157580188
1 => float 0.09353053131525
2 => float 0.056112567274848
3 => float 0.061736106228142
现在,我想要的是每组的总和。类似的东西:
[0] [0] + [0] [1] + [0] [2] + [0] [3]
使用此代码,我收到此错误:array_sum()期望参数1为数组,双给定
for ($i = 0; $i < $numCol; $i++) {
for ($j = 0; $j < $numCol; $j++) {
$sumResult[] = array_sum($result[$i][$j]);
}
}
答案 0 :(得分:2)
您需要将数组传入array_sum
但您要明确传递每个值。试试这个:
for ($i = 0; $i < $numCol; $i++) {
$sumResult[] = array_sum($result[$i]);
}