将多维数组中的所有值都获取到单个数组中

时间:2012-02-05 14:18:26

标签: php arrays

  

可能重复:
  How to Flatten a Multidimensional Array?

阵列:

itemA => value
  itemA1 => value
  itemA2 => value
    itemA11 => value
itemB => value

and so on...

如何获得这样收集的值:

[0] => value (from itemA)
[1] => value (from itemA1)
[2] => value (from itemA2)
[3] => value (from itemA11)
[4] => value (from itemB)
...

1 个答案:

答案 0 :(得分:4)

使用array_walk()编写自己的数组函数? 或者,我不知道,但也许使用array_values()?编辑:我发现了这个:

 $a = array(1,2,array(3,4, array(5,6,7), 8), 9); 
 $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($a)); 
 foreach($it as $v) { 
   echo $v, " "; 
 }