$GLOBALS
$GLOBALS — 引用全局作用域中可用的全部变量
一个包含了全部变量的全局组合 数组 。变量的名字就是数组的键。
Example #1 $GLOBALS 范例
<?php
function test () {
$foo = "local variable" ;
echo '$foo in global scope: ' . $GLOBALS [ "foo" ] . "\n" ;
echo '$foo in current scope: ' . $foo . "\n" ;
}
$foo = "Example content" ;
test ();
?>
以上例程的输出类似于:
$foo in global scope: Example content $foo in current scope: local variable
Note:
“Superglobal”也称为自动化的全局变量。这就表示其在脚本的所有作用域中都是可用的。不需要在函数或方法中用 global $variable; 来访问它。
Note: 变量可用性
与所有其他超全局变量不同, $GLOBALS 在PHP中总是可用的。