<?php $arr = Array ( Array ( "id" => 99, "fruit" => "Apple", "color" => "Green" ), Array ( "id" => 99, "fruit" => "Apple", "color" => "Red" ), Array ( "id" => 555, "fruit" => "Banana", "color" => "Yellow" ) ); $ids = array_column($arr, "id"); Foreach(array_unique($ids) as $id){ $temp = array_values(array_intersect_key($arr, array_intersect($ids, [$id]))); $new[$id] = ['fruit' => $temp[0]['fruit'], 'color' => array_column($temp, "color")]; } Var_dump($new);
You have javascript disabled. You will not be able to edit any code.