在Laravel,PHP中简化多维数组

时间:2017-10-23 21:39:13

标签: php arrays object laravel-5

我在Laravel Applicaiton中从我的控制器返回一组数据。但是,我想简化数据,以便我可以更轻松地访问属性。这就是我所拥有的:

"sub_categories": [
    [
        {
            "id": 1,
            "name": "Accounting"
        }
    ],
    [
        {
            "id": 2,
            "name": "Business"
        }
    ],
    [
        {
            "id": 3,
            "name": "Engineering"
        }
    ],
]

这就是我想要归档的内容:

"sub_categories": [ 
    {
        "id": 1,
        "name": "Accounting"
    },
    {
        "id": 2,
        "name": "Business"
    },  
    {
        "id": 3,
        "name": "Engineering"
    }
]

0 个答案:

没有答案