PHP中将多维数组转换为单个数组

PHP中将多维数组转换为单个数组

本文介绍了在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.

任何帮助表示赞赏.

推荐答案

尝试foreach循环,然后 array_merge()

Try foreach loop then array_merge()

$result = [];

foreach ($array as $value) {
    $result = array_merge($result, $value);
}

var_dump($result);

这篇关于在Codeigniter PHP中将多维数组转换为单个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 01:58