有没有办法通过递归数组?
$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)
任何想法? 菲利普
答案 0 :(得分:0)
然后只过滤以获得您想要的值
$filter = array('format', 'test');
foreach (array_intersect_key($GLOBALS, array_flip($filter)) as $key => $value) {
echo $key."<br>";
}