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.

图片转代码服务由CSDN问答提供 功能建议

我有一个多维数组,如下所示

  Array \  n(
 [0] =>数组
(
 [0] => stdClass对象
(
 [id] => 237 
)
 [1] => stdClass对象\  n(
 [id] => 228 
)
)
 [1] =>数组
(
 [0] => stdClass对象
(
 [id] =>  247 
)
 [1] => stdClass对象
(
 [id] => 238 
)
)
)
 
   
 
 <  p>我想转换成单个数组,如下所示 
 
 
  Array 
(
 [0] =&gt; stdClass Object 
(
 [id] =&gt;  ; 237 
)
 [1] =&gt; stdClass对象
(
 [id] =&gt; 228 
)
 [2] =&gt; stdClass对象
(
 [id] =&gt;  ; 24  7 
)
 [3] =&gt;  stdClass对象
(
 [id] =&gt; 238 
)
)
   
 
 

我尝试过以下解决方案将多维数组转换为单个数组

但结果 没有得到它的即将到来

如何获得上述输入所需的结果。

任何帮助表示赞赏。 < / DIV>

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

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条)

相关推荐 更多相似问题