是否可以列出 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:39:08  来源:igfitidea点击:

Is it possible to List Out All the Global variables in PHP?

phpglobal-variables

提问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:

更多文档:

回答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

回答by hjpotter92

Well, there does exist a $GLOBALSvariable in PHP.

好吧,$GLOBALSPHP 中确实存在一个变量。

But you can't do a var_export()on it. It'll lead to an error like: Nesting level too deep - recursive dependency?

但是你不能var_export()对它做任何事情。它会导致如下错误:嵌套级别太深 - 递归依赖?

回答by FThompson

The reserved $GLOBALSvariable is an array containing all global variables.

保留$GLOBALS变量是一个包含所有全局变量的数组。

In the array, the keys are variable names and the values are variable values.

在数组中,键是变量名,值是变量值。