This article mainly introduces the scope of PHP, has a certain reference value, now share to everyone, the need for friends can refer to
The area to which the variable can be accessed.
JS in scope:
Global scope: can be used anywhere (outside the function and inside the function)
Local scope: Can only be used inside a function
PHP also has two scopes: global scope and local scope
Global scope: can only be used outside the function
Local scope: Can only be used inside a function
Global scope refers to a variable defined outside a function, and a local scope refers to a variable defined inside a function
Internal cannot access external
External cannot access internal
Global scope can be accessed using $globals[' global scope variable ' in a local scope
Note: $GLOBALS is a variable that refers to the global scope itself
PHP also provides a keyword: global
Global is the address of the variable of the global scope, replicates it, and creates a new variable name with the same name within the local scope, assigning the external address to the local variable.
Syntax: global variable name;
Variable name = value;
The area to which the variable can be accessed.
JS in scope:
Global scope: can be used anywhere (outside the function and inside the function)
Local scope: Can only be used inside a function
PHP also has two scopes: global scope and local scope
Global scope: can only be used outside the function
Local scope: Can only be used inside a function
Global scope refers to a variable defined outside a function, and a local scope refers to a variable defined inside a function
Internal cannot access external
External cannot access internal
Global scope can be accessed using $globals[' global scope variable ' in a local scope
Note: $GLOBALS is a variable that refers to the global scope itself
PHP also provides a keyword: global
Global is the address of the variable of the global scope, replicates it, and creates a new variable name with the same name within the local scope, assigning the external address to the local variable.
Syntax: global variable name;
Variable name = value;
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!