是否可以列出 PHP 中的所有全局变量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12488661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to List Out All the Global variables in PHP?
提问by Hemi
Is it possible to list out all the Global Variable. Such , as to print all session variable we can use print_r($_SESSION);as the same way, if i want to know how many Global variables are define in my site. is it possible? Please Help.
是否可以列出所有全局变量。例如,print_r($_SESSION);如果我想知道在我的站点中定义了多少全局变量,我们可以以相同的方式打印所有会话变量。是否可以?请帮忙。
I need the list which can show me all the Global variables List in PHP.
我需要可以显示 PHP 中所有全局变量列表的列表。
回答by Jordan Arseno
Yes, PHP $GLOBALSarray will show you.
是的,PHP$GLOBALS数组会告诉你。
<?php
echo "<pre>";
print_r($GLOBALS);
echo "</pre>";
回答by Tadeck
To get names of all global variables do this:
要获取所有全局变量的名称,请执行以下操作:
array_keys($GLOBALS)
More docs:
更多文档:
- on array_keys(): http://php.net/manual/en/function.array-keys.php
- on $GLOBALS: http://php.net/manual/en/reserved.variables.globals.php
- 关于 array_keys():http: //php.net/manual/en/function.array-keys.php
- 在 $GLOBALS 上:http: //php.net/manual/en/reserved.variables.globals.php
回答by NullPoiиteя
$GLOBALS— References all variables available in global scope also check this PHP global or $GLOBALShere you find many important and useful thing about $GLOBALS
$GLOBALS— 引用全局范围内可用的所有变量,还可以检查这个PHP global 或 $GLOBALS在这里你会发现很多重要和有用的东西$GLOBALS

