遍历递归数组


Walk through recursive array

有没有一种方法可以遍历递归数组?

$GLOBALS看起来像这样:

array(7) {
  ["_GET"]=>
    array(0) {
    }
  ["_POST"]=>
    array(0) {
    }
 ["_COOKIE"]=>
    array(1) {
    ["PHPSESSID"]=>
    string(26) "n02ngn8h62sbtm4kgijdp5pnc1"
 }
 ["_FILES"]=>
   array(0) {
   }
 ["GLOBALS"]=>
   *RECURSION*
   ["format"]=>
   object(Format)#1 (0) {
   }
   ["test"]=>
   object(Test)#2 (0) {
  }
}

我想要一个像[format] => object(format), [test] => object(test) 这样的输出

有什么想法吗?Philip

然后只需过滤即可获得您想要的值

$filter = array('format', 'test');
foreach (array_intersect_key($GLOBALS, array_flip($filter)) as $key => $value) {
    echo $key."<br>";
}