Home >Backend Development >PHP Tutorial >php learning 2
PHP also has two scopes: global scope and local scope
Global scope: can only be used outside the function, the outside cannot access the inside
Local scope: can only be used inside the function, and cannot access the outside
Global scope refers to variables defined outside the function, and local scope refers to variables defined inside the function
A. You can use $GLOBALS[‘global scope variables’] in the local scope to access the global scope
B. PHP also provides a keyword: global
Global copies the address of the variable in the global scope, then creates a new variable name with the same name in the local scope, and assigns the external address to the local variable.
Syntax: global variable name;
Variable name = value;
Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above has introduced PHP Learning 2, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.