Get sum of arrays inside array



PHP Snippet 1:

$arrays = [[0, 176000], [0,500], [0, 3960000]];
print_r(array_map('array_sum', array_map(null, ...$arrays)));

PHP Snippet 2:

    $a = collect([[0, 176000], [0,500], [0, 3960000]]);
    $b = new Collection;
    foreach ($a as $k => $e) {
        $b->push ( $a->pluck($k)->sum() );
    }

    $c = $b->take(2); // Result is going to be here

PHP Snippet 3:

<?php
$arrays = [[0, 176000], [0,500], [0, 3960000]];
$new_arrays = [];
foreach ($arrays as $key => $val) {
  $new_arrays[0] += $val[0];
  $new_arrays[1] += $val[1];
}
print_r($new_arrays);

PHP Snippet 4:

$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);

PHP Snippet 5:

array(5) {
  [0]=>
  int(10)
  ["A"]=>
  int(176000)
  ["b"]=>
  int(500)
  [1]=>
  int(3960500)
  [2]=>
  int(400)
}

PHP Snippet 6:

$arrays = [[0, 176000], [0,500], [0, 3960000]];
var_export(
    array_map(fn() => array_sum(func_get_args()), ...$arrays)
);

PHP Snippet 7:

var_export(
    array_map(fn(...$col) => array_sum($col), ...$arrays)
);

PHP Snippet 8:

array (
  0 => 0,
  1 => 4136500,
)