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

preferences:
24.32 ms | 405 KiB | 5 Q