Skip to content

TypeScript code snippet – 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);
See also  Python code snippet - How to get scrapy output file in xml file?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.