Home > Article > Backend Development > A detailed introduction to the scope in php based on the code
The following is the scope in PHP that I have compiled for you. Interested students can take a look.
Local scope: Inside a function:
Super Global scope: refers to all code scope
Global scope: is the scope that is not inside the function--outside the function
Note: The local scope cannot access the global scope
If you want to use global variables locally
<?php $v1 = 1; function f1() { echo "<br /> v1 = $v1"; // 未定义的v1; // 若要局部访问全局 /* global $v1; // 声明外部变量的局部变量,此时就可以使用全局变量v1了 */ } ?>
At this time we can use $GLOBAL['v1'] to access
$GLOBAL is a collection of global variables Super global variables.
If we $ When a certain unit of GLOBAL is unset, it will be completely deleteThe variable
We can also assign values to variables through $GLOBAL
unset($GLOBALS['v6']);
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Explain in detail the distinction between require, include, and use in PHP
Explain in detail the key to PHP classes and methods Word tutorial
# Specific usage of namespace and use
The above is the detailed content of A detailed introduction to the scope in php based on the code. For more information, please follow other related articles on the PHP Chinese website!