array(11) { [5640]=> array(7) { [0]=> float(2073571) [1]=> float(2013735) [2]=> float(1754255) [3]=> float(1680738) [4]=> float(2941359) [5]=> float(1311749) [6]=> float(811265) } [18348]=> array(7) { [0]=> float(530882) [1]=> int(0) [2]=> int(0) [3]=> int(0) [4]=> int(0) [5]=> int(0) [6]=> float(248562) } [18354]=> array(7) { [0]=> int(0) [1]=> float(531189) [2]=> float(1621976) [3]=> float(1197067) [4]=> float(597600) [5]=> float(1052615) [6]=> float(735903) } [18953]=> array(7) { [0]=> int(0) [1]=> int(0) [2]=> int(0) [3]=> int(0) [4]=> int(0) [5]=> float(218906) [6]=> int(0) } [20693]=> array(7) { [0]=> int(0) [1]=> int(0) [2]=> int(0) [3]=> int(0) [4]=> int(0) [5]=> int(0) [6]=> float(98622) } [20704]=> array(7) { [0]=> int(0) [1]=> int(0) [2]=> int(0) [3]=> int(0) [4]=> int(0) [5]=> int(0) [6]=> float(140237) } [20964]=> array(7) { [0]=> int(0) [1]=> int(0) [2]=> int(0) [3]=> int(0) [4]=> float(321428) [5]=> int(0) [6]=> int(0) } [25734]=> array(7) { [0]=> float(1170948) [1]=> float(768867) [2]=> float(728450) [3]=> float(833734) [4]=> float(597185) [5]=> float(263393) [6]=> int(0) } [26835]=> array(7) { [0]=> int(0) [1]=> int(0) [2]=> float(1060214) [3]=> float(502962) [4]=> int(0) [5]=> int(0) [6]=> int(0) } [27334]=> array(7) { [0]=> float(3018626) [1]=> float(2049465) [2]=> int(0) [3]=> int(0) [4]=> int(0) [5]=> int(0) [6]=> int(0) } [28246]=> array(7) { [0]=> float(618913) [1]=> float(699874) [2]=> float(845265) [3]=> float(698149) [4]=> float(942333) [5]=> float(234815) [6]=> int(0) } }用php请求二维数组每个数组之和
时间: 2023-12-09 08:03:43 浏览: 35
可以使用 PHP 中的 `array_map()` 函数和 `array_sum()` 函数来求二维数组每个数组之和。具体实现如下:
```php
$arr = array(
array(2073571, 2013735, 1754255, 1680738, 2941359, 1311749, 811265),
array(530882, 0, 0, 0, 0, 0, 248562),
array(0, 531189, 1621976, 1197067, 597600, 1052615, 735903),
array(0, 0, 0, 0, 0, 218906, 0),
array(0, 0, 0, 0, 0, 0, 98622),
array(0, 0, 0, 0, 0, 0, 140237),
array(0, 0, 0, 0, 321428, 0, 0),
array(1170948, 768867, 728450, 833734, 597185, 263393, 0),
array(0, 0, 1060214, 502962, 0, 0, 0),
array(3018626, 2049465, 0, 0, 0, 0, 0),
array(618913, 699874, 845265, 698149, 942333, 234815, 0)
);
$sum_arr = array_map("array_sum", $arr);
print_r($sum_arr);
```
以上代码中,使用 `array_map()` 函数和 `array_sum()` 函数对二维数组进行遍历和求和操作。`array_map()` 函数传递了一个回调函数 `"array_sum"`,它会对每个数组进行求和操作。最后输出求和后的数组 `$sum_arr` 即可。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)