how to collect array of objects in one value key in laravel

The solution for “how to collect array of objects in one value key in laravel” can be found here. The following code will assist you in solving the problem.

$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);

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in