我有两个多维数组。如果键相同,那么我想得到总和,我该怎么做。一个是——
Array
(
[2018-08-02] => Array
(
[male] => 1
[female] => 0
)
[2018-08-07] => Array
(
[male] => 1
[female] => 0
)
[2018-08-09] => Array
(
[male] => 1
[female] => 5
)
)
第二个是-一个是-
Array
(
[2018-08-02] => Array
(
[male] => 3
[female] => 4
)
[2018-08-07] => Array
(
[male] => 1
[female] => 5
)
[2018-08-06] => Array
(
[male] => 2
[female] => 3
)
)
所以我的结果是
Array
(
[2018-08-02] => Array
(
[male] => 4
[female] => 4
)
[2018-08-07] => Array
(
[male] => 2
[female] => 5
)
[2018-08-09] => Array
(
[male] => 1
[female] => 5
)
[2018-08-06] => Array
(
[male] => 2
[female] => 3
)
)
代码是
foreach ($reportlist as $reportlists){
$daterep=$reportlists['act_date'];
$arr[$daterep]['male']=$reportlists['male_cnt'];
$arr[$daterep]['female']=$reportlists['female_cnt'];
}
foreach ($ureportlist as $ureportlists){
$daterep=$rueportlists['act_date'];
$arr2[$daterep]['male']=$reportlists['male_cnt'];
$arr2[$daterep]['female']=$reportlists['female_cnt'];
}