3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [1, 2014, 'context' => 'aaa'], [12, 2014, 'context' => 'aaa'], [5, 2014, 'context' => 'zzz'], ]; foreach ($array as $i => &$row) { if (!isset($ref[$row['context']])) { $ref[$row['context']] = &$row[0]; } else { $ref[$row['context']] += $row[0]; unset($array[$i]); } } var_export($array);

preferences:
94.05 ms | 404 KiB | 5 Q