Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #collect #array #objects #key #laravel
ADD COMMENT
Topic
Name
2+6 =