我有一个像这样的数组。
Array
(
[162 D Dr.] => Array
(
[smi_discover] => 0
[smi_totalmonthccsales] => 12568
[smi_amex] => 0
[smi_visamc] => 12568
[smi_ebt] => 0
[smi_includeindeal] => 0
[smi_debit] => 0
[smi_batches] => 7
)
[16ee22 D Dr.] => Array
(
[smi_discover] => 0
[smi_totalmonthccsales] => 125368
[smi_amex] => 0
[smi_visamc] => 12568
[smi_ebt] => 0
[smi_includeindeal] => 0
[smi_debit] => 0
[smi_batches] => 7
)
)
这把钥匙 [162 D Dr.] 可以是任何东西。[16e2 D Dree],[332 D44 Drdds]。
我如何循环遍历并添加 smi_totalmonthccsales 并将其添加到父数组中,所以我最终会得到这样的结果
['total'] = sum of smi_totalmonthccsales in both address arrays
[162 D Dr.] => Array
(
[smi_discover] => 0
[smi_totalmonthccsales] => 12568
[smi_amex] => 0
[smi_visamc] => 12568
[smi_ebt] => 0
[smi_includeindeal] => 0
[smi_debit] => 0
[smi_batches] => 7
)
我试过了
foreach($newnewArr as $key) {
if(isset($key['smi_totalmonthccsales']) && isset($key)){
$ccArray[$key]['total'] +=$key['smi_totalmonthccsales'];
} else {
$ccArray[$key]['total'] = 0;
}
}