how to collect array of objects in one value key in laravel code example
Example: how to collect array of objects in one value key in laravel
$arr = json_decode($str, true);
$names = array_column($arr, "name");
$codes = array_column($arr, "code");
foreach(array_unique($names) as $name){
$new[$name] = array_intersect_key($codes, array_intersect($names, [$name]));
}
var_dump($new);