I have this object from transfomers:
{
"lists": [
{
"product": {
"id": "642c1986-c383-4710-8412-3b9c80ab461e",
"parent_category_id": "38da81a7-2507-4fcf-be0b-aff7c4808737",
"category_id": "6a00814c-c2ea-4cd1-9414-e622c4196c45",
"name": "Skinny",
"description": "Skinny",
"image": "",
"listings": {
"data": [
{
"id": "cffc889f-41d5-40eb-8fc3-f64c157d748d",
"price": "112.00",
"merchant": {
"id": "054763eb-a1ae-44d1-8a25-77e5dfc2cd52",
"name": "Example"
}
}
]
}
}
},
{
"product": {
"id": "d9488bc9-0df3-4eab-a39f-634e34334261",
"parent_category_id": "38da81a7-2507-4fcf-be0b-aff7c4808737",
"category_id": "6a00814c-c2ea-4cd1-9414-e622c4196c45",
"name": "Raw",
"description": "Raw",
"image": "",
"listings": {
"data": [
{
"id": "b3b4416b-7936-417f-afb3-03b7368bebfb",
"price": "112.00",
"merchant": {
"id": "054763eb-a1ae-44d1-8a25-77e5dfc2cd52",
"name": "Example"
}
}
]
}
}
}
]
}
Inside similars > product there is listing object. I want to remove "data" key but keep the collection.
I've tried using foreach but not working:
foreach ($transformSimilar as $key => $row) {
$transformSimilar[$key]['product']['listings'] = $transformSimilar[$key]['product']['listings']['data'];
}
Is there any better solution to achieve this?
solve it:
foreach ($transform['lists'] as $key => $row) {
$transform['lists'][$key]['product']['listings'] = $row['product']['listings']['data'];
}