Try something like
$array['facilities'] = $array['facilities']['data'];
In foreach or each for collections If you use collection try find something in docs http://laravel.com/docs/5.1/collections
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I've got an multidimensional array.
{
"id": "13",
"name": "Example",
"location_name": "NY",
"phone": [
{
"number": "0617357707"
}
],
"facilities": {
"data": [
{
"name": "AC"
},
{
"name": "Wi-Fi"
}
]
}
}
The problem I want to solve is at "facilities". Inside facilities, there is a data object. How can I remove the data without removing the content "data"?
Expected result:
{
"id": "13",
"name": "Example",
"location_name": "NY",
"phone": [
{
"number": "0617357707"
}
],
"facilities": [
{
"name": "AC"
},
{
"name": "Wi-Fi"
}
]
}
I've tried using array_walk or flatten but not getting it right.
Try something like
$array['facilities'] = $array['facilities']['data'];
In foreach or each for collections If you use collection try find something in docs http://laravel.com/docs/5.1/collections
Please or to participate in this conversation.