从阵列集PHP删除父级阵列和合并节点 [英] php Remove parent level array from set of arrays and merge nodes

查看:77
本文介绍了从阵列集PHP删除父级阵列和合并节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可怕与操作数组......给这个结构我想删除顶层阵列和所有子集合并成一个平面数组:

I am terrible with manipulating arrays...given this structure I want to remove the top level array and merge all subsets into one flat array:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => hey.com
                )

            [1] => Array
                (
                    [0] => you.com
                )
        )
    [1] => Array
        (
            [0] => Array
                (
                    [0] => this.com
                )

            [1] => Array
                (
                    [0] => rocks.com
                )
        )
)

到所需的结构:

Array
    (
        [0] => hey.com
        [1] => you.com
        [2] => this.com
        [3] => rocks.com
    )

速度是至关重要的 - 我们将与成千上万的结果要处理

Speed is essential - we will be dealing with hundreds of thousands of results

推荐答案

您可以使用 RecursiveArrayIterator

$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($data));
$list = iterator_to_array($it,false);
var_dump($list);

输出

array (size=4)
  0 => string 'hey.com' (length=7)
  1 => string 'you.com' (length=7)
  2 => string 'this.com' (length=8)
  3 => string 'rocks.com' (length=9)

请参阅简单演示

这篇关于从阵列集PHP删除父级阵列和合并节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆