卸下外部阵列并更改显示阵列

时间:2018-08-03 12:27:12

标签: php laravel multidimensional-array

如果数组中有一个数组,如何在此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)返回具有键的数组。请帮忙。

1 个答案:

答案 0 :(得分:0)

这里是:

$array = []; // your array
$new_array = [];
foreach ($array as $item) {
    $new_array[$item->id] = $item;
}