3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = array ( array ('Shop' => 3, 'Weight' => 4), array ('Shop' => 3, 'Weight' => 5), array ('Shop' => 3, 'Weight' => 1) ); print_r($array); $result = array (); foreach($array as $item) { if (isset($result[$item['Shop']])) { $result[$item['Shop']] += $item['Weight']; } else { $result[$item['Shop']] = $item['Weight']; } } print_r($result);
based on OaLYL
Output for 4.3.0 - 7.2.0
Array ( [0] => Array ( [Shop] => 3 [Weight] => 4 ) [1] => Array ( [Shop] => 3 [Weight] => 5 ) [2] => Array ( [Shop] => 3 [Weight] => 1 ) ) Array ( [3] => 10 )