3v4l.org

run code in 300+ PHP versions simultaneously
<?php $estimate = array( array( 'gear' => 'MMG', 'total' => 315, 'efforts' => 9, 'afh' => 18 ), array( 'gear' => 'MMG', 'total' => 400, 'efforts' => 2, 'afh' => 6, ), array( 'gear' => 'BOO', 'total' => 200, 'efforts' => 20, 'afh' => 16, ), array( 'gear' => 'BOB', 'total' => 250, 'efforts' => 20, 'afh' => 16, ) ); $result = array_reduce($estimate, function($carry, $item) { if (!isset($carry[$item["gear"]])) { $carry[$item["gear"]] = $item; return $carry; } $carry[$item["gear"]]["total"] += $item["total"]; $carry[$item["gear"]]["efforts"] += $item["efforts"]; $carry[$item["gear"]]["afh"] += $item["afh"]; return $carry; }); print_r($result);
Output for 7.1.0 - 7.1.33, 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.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
Array ( [MMG] => Array ( [gear] => MMG [total] => 715 [efforts] => 11 [afh] => 24 ) [BOO] => Array ( [gear] => BOO [total] => 200 [efforts] => 20 [afh] => 16 ) [BOB] => Array ( [gear] => BOB [total] => 250 [efforts] => 20 [afh] => 16 ) )

preferences:
75.4 ms | 408 KiB | 5 Q