php Remove parent level array from set of arrays and merge nodes

后端 未结 6 1059
执念已碎
执念已碎 2020-12-14 09:40

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]         


        
6条回答
  •  温柔的废话
    2020-12-14 10:06

    You can use RecursiveArrayIterator

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

    Output

    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)
    

    See Simple Demo

提交回复
热议问题