<?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);
You have javascript disabled. You will not be able to edit any code.