我是php新手。我需要两个数组的总和,但没有得到正确的输出。我的数组是以这种方式出现的。
这是我的第一个数组。
Array
(
[1] => Array
(
[1] => Array
(
[-10] => 21787048.7293
[-5] => 21816115.9548
[-1] => 21839369.7352
[0] => 21845183.1803
[1] => 21850996.6254
[5] => 21874250.4058
[10] => 21903317.6313
)
)
[2] => Array
(
[2] => Array
(
[-10] => 21147607.6407
[-5] => 21496395.4105
[-1] => 21775425.6263
[0] => 21845183.1803
[1] => 21914940.7343
[5] => 22193970.9501
[10] => 22542758.7199
)
)
)
这是第二个数组。
Array
(
[1] => Array
(
[1] => Array
(
[-10] => 26101989.9443
[-5] => 26131057.1698
[-1] => 26154310.9501
[0] => 26160124.3952
[1] => 26165937.8403
[5] => 26189191.6207
[10] => 26218258.8462
)
)
[2] => Array
(
[2] => Array
(
[-10] => 25462548.8556
[-5] => 25811336.6254
[-1] => 26090366.8413
[0] => 26160124.3952
[1] => 26229881.9492
[5] => 26508912.1651
[10] => 26857699.9349
)
)
)
我需要按键对这两个数组求和。请帮帮我。
这是我的代码。我的两个数组是 $pretax_income,$earning。
foreach($pretax_income as $k=>$value)
{
foreach($value as $v=>$val)
{
foreach($val as $u=>$valArr) {
$comboarray[$elno] = $valArr[$k][$v][$u] + $earning[$k][$v][$u];
}
}
} print_r($comboarray);