如果数组中有一个数组,如何在此laravel代码中删除外部数组。当前返回数组。
return view($this->_viewDefaultFile)
->with('id', $this->_formId)
->with('class', $this->_formClass)
->with('elements', $this->_formElements)
->with('ManageJs', $this->_formManageJs);
当前结果
[
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"
}
]
但首选输出
[
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"
}
]
所以我想用(ID)返回具有键的数组。请帮忙。
答案 0 :(得分:0)
这里是:
$array = []; // your array
$new_array = [];
foreach ($array as $item) {
$new_array[$item->id] = $item;
}