Home >Backend Development >PHP Problem >What is the usage of $GLOBALS in php
The usage of $GLOBALS in php is to reference all variables available in the global scope, such as [$GLOBALS["foo"]]. $GLOBALS is a global combined array containing all variables.
The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.
$GLOBALS is used to reference all variables available in the global scope. It is a global combined array containing all variables. The name of the variable is the key of the array.
Example:
<?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(); ?>
The output of the above routine is similar to:
$foo in global scope: Example content $foo in current scope: local variable
Related video sharing: php video tutorial
The above is the detailed content of What is the usage of $GLOBALS in php. For more information, please follow other related articles on the PHP Chinese website!