3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = Array ( '0' => Array ( 'emp_firstname' => 'Alistair', 'non_pm' => 'AMZ', 'sum' => 2 ), '1' => Array ( 'emp_firstname' => 'Shakkeer', 'non_pm' => 'SHK', 'sum' => 3 ), '2' => Array ( 'emp_firstname' => 'Waqas', 'non_pm' => 'WAS', 'sum' => 12 ), '3' => Array ( 'emp_firstname' => 'Zain', 'non_pm' => 'ZAI', 'sum' => 9 ), '4' => Array ( 'emp_firstname' => 'Shakkeer', 'gud_pmeditor' => 'SHK', 'sum' => 4 ), '5' => Array ( 'emp_firstname' => 'Zain', 'gud_pmeditor' => 'ZAI', 'sum' => 2 ) ); $res=[]; foreach($arr as $val){ if(array_key_exists($val['emp_firstname'], $res)) $res[$val['emp_firstname']]['sum'] = ($res[$val['emp_firstname']]['sum'] + $val['sum']); else $res[$val['emp_firstname']] = $val; } print_r(array_values($res));
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 ( [0] => Array ( [emp_firstname] => Alistair [non_pm] => AMZ [sum] => 2 ) [1] => Array ( [emp_firstname] => Shakkeer [non_pm] => SHK [sum] => 7 ) [2] => Array ( [emp_firstname] => Waqas [non_pm] => WAS [sum] => 12 ) [3] => Array ( [emp_firstname] => Zain [non_pm] => ZAI [sum] => 11 ) )

preferences:
76.91 ms | 409 KiB | 5 Q