Can you show an example of how you would expect the outout to look?
Sep 20, 2021
8
Level 1
Push data from a array to a collection with key and value
Hi, I'm back with a question about how I could push data from an array into a collection of keys and values I have this collection
#items: array:6 [
0 => array:8 [
"condition" => "used"
"brand" => "LG"
"gender" => ""
"age_group" => ""
"color" => ""
"size" => ""
"shipping" => "US::Standard:14.95 USD"
"shipping_weight" => "9.2 lbs"
]
1 => array:8 [
"condition" => "new"
"brand" => "BBC"
"gender" => ""
"age_group" => ""
"color" => ""
"size" => ""
"shipping" => "US::Express:3.80 USD"
"shipping_weight" => ""
]
And I would like the value on the left to be a key and the value on the right a value So I try to collect the data but in the end I only have a worthless key what idea do you have to put all that data in a key value like he wants me to do below?
$finalCollection = new Collection();
foreach ($attributesCollection as $attributeCollection) {
foreach ($attributeCollection as $key => $value) {
$finalCollection = collect(['key' => $key, 'value' => $value]);
}
}
Please or to participate in this conversation.