If you have an array within an array, how can you remove the outer array in this laravel code. Current return array.
return view($this->_viewDefaultFile)
->with('id', $this->_formId)
->with('class', $this->_formClass)
->with('elements', $this->_formElements)
->with('ManageJs', $this->_formManageJs);
Current Results
[
0 {
"id": "id",
"group": 0,
"type": "hidden",
"label": "",
"options": [
],
"value": "1"
},
1 {
"id": "taskstream",
"group": 0,
"type": "text",
"label": "Task Stream",
"options": {
"class": "",
"validation": "required"
},
"value": "System down for maintenance"
}
]
But preferred output
[
id {
"id": "id",
"group": 0,
"type": "hidden",
"label": "",
"options": [
],
"value": "1"
},
taskstream {
"id": "taskstream",
"group": 0,
"type": "text",
"label": "Task Stream",
"options": {
"class": "",
"validation": "required"
},
"value": "System down for maintenance"
}
]
So i want to return the Array with (ID) has the key. Any help please.
Here it is:
$array = []; // your array
$new_array = [];
foreach ($array as $item) {
$new_array[$item->id] = $item;
}