doutuanxiao4619 2018-05-22 05:29
浏览 37
已采纳

在codeigniter php中将多维数组转换为单个数组

I have a multidimensional array as shown below

Array
(
    [0] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 237
                )
            [1] => stdClass Object
                (
                 [id] => 228
                )
        )
    [1] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 247
                )
            [1] => stdClass Object
                (
                 [id] => 238
                )
        )
)

I want to convert into single array as shown below

Array
(
        [0] => stdClass Object
        (
            [id] => 237
        )
        [1] => stdClass Object
        (
            [id] => 228
        )
        [2] => stdClass Object
        (
            [id] => 247
        )
        [3] => stdClass Object
        (
            [id] => 238
        )
)

I have tried with the following solution Convert multidimensional array into single array

But the result am not getting Its Coming Null

How to get the desired result for the above input.

Any help appreciated.

  • 写回答

2条回答 默认 最新

  • dongmeixian9665 2018-05-22 05:36
    关注

    Try foreach loop then array_merge()

    $result = [];
    
    foreach ($array as $value) {
        $result = array_merge($result, $value);
    }
    
    var_dump($result);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?