How to merge subarray in PHP most easily?

后端 未结 7 563
渐次进展
渐次进展 2020-12-03 22:32
$arr[] = array(\'A\',\'B\');
$arr[] = array(\'C\',\'B\');
...

I need to get the merged result of all sub array of $arr .

And f

7条回答
  •  执念已碎
    2020-12-03 23:17

    This answer is based on Felix Kling post. It's more accurate version with fixing "non array" sub-elements.

    $res = array_reduce($res, function(&$res, $v) {
                                return array_merge($res, (array) $v);
                            }, array());
    

提交回复
热议问题