我有来自变形体的这个对象:
{
"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"
}
}
]
}
}
}
]
}
内部类似物>产品有上市对象。我想删除“数据”键但保留集合。
我尝试过使用foreach但没有工作:
foreach ($transformSimilar as $key => $row) {
$transformSimilar[$key]['product']['listings'] = $transformSimilar[$key]['product']['listings']['data'];
}
有没有更好的解决方案来实现这一目标?
答案 0 :(得分:0)
解决它:
foreach ($transform['lists'] as $key => $row) {
$transform['lists'][$key]['product']['listings'] = $row['product']['listings']['data'];
}