<?php $arr=array( Array ( 0 => 3, 1 => 1 ), Array ( 0 => 3, 1 => 2 ), Array ( 0 => 3, 1 => 128 ), Array ( 0 => 39, 1 => 4 )); $col0 = array_column($arr, 0); $col1 = array_column($arr, 1); Foreach(array_unique($col0) as $val){ $res[] = [$val, array_sum(array_intersect_key($col1, array_intersect($col0,[$val])))]; } Var_dump($res);
You have javascript disabled. You will not be able to edit any code.