3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( array('city' => 'NewYork', 'cash' => '1000'), array('city' => 'Philadelphia', 'cash' => '2300'), array('city' => 'NewYork', 'cash' => '2000'), ); $newarray = array(); foreach($arr as $ar) { foreach($ar as $k => $v) { if(array_key_exists($v, $newarray)) $newarray[$v]['cash'] = $newarray[$v]['cash'] + $ar['cash']; else if($k == 'city') $newarray[$v] = $ar; } } print_r($newarray);
based on uhqYM
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.27, 7.4.0 - 7.4.15, 8.0.0 - 8.0.2
Array ( [NewYork] => Array ( [city] => NewYork [cash] => 3000 ) [Philadelphia] => Array ( [city] => Philadelphia [cash] => 2300 ) )