<?php
$arrays = [[0,"A" => 176000], [0, "b" => 500], [0, 3960000, 200], [10, 500, 200]];
foreach($arrays as $sub){
foreach($sub as $key => $num){
if(!isset($new[$key])) $new[$key] =0;
$new[$key] += $num;
}
}
var_dump($new);
- Output for 5.6.38, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- array(5) {
[0]=>
int(10)
["A"]=>
int(176000)
["b"]=>
int(500)
[1]=>
int(3960500)
[2]=>
int(400)
}
preferences:
363.58 ms | 408 KiB | 5 Q