Chris1904
$collection = collect([
[
"Background" => "Layer-1",
"value" => "Static",
],
[
"Eyes" => "Layer-2",
"value" => "Up and down",
],
[
"Mouth" => "Layer-3",
"value" => "British",
],
[
"Hair" => "Layer-4",
"value" => "Pherb",
],
[
"Eyebrows" => "Layer-5",
"value" => "Little Sad",
],
[
"Glasses" => "Layer-6",
"value" => "none",
],
]);
$goal= [];
if (array_key_first($collection->first()) !== 'trait_type') {
$goal = $collection->map(fn ($attribute) => [array_key_first($attribute) => $attribute['value']])
->toArray();
dd(array_merge(...$goal));
}
array:6 [
"Background" => "Static"
"Eyes" => "Up and down"
"Mouth" => "British"
"Hair" => "Pherb"
"Eyebrows" => "Little Sad"
"Glasses" => "none"
]