Home >Backend Development >PHP Tutorial >The meaning and function of PHP global
It is said that not writing articles does not count as a skilled person, next! This is how I record my growth as a newbie!
The scope of variables is something that every programmer must consider, but it is very different from C++ in PHP! For example, if the variable name inside and outside the function is the same, but it cannot be overwritten, if you want to refer to the variable outside the function, you need to use global. Next, check out the following demo:
$num =10;
function test(){
$num = $num *10;
}
test();
echo $num;
output 10.
$num =10;
function test(){
global $num;
$num = $num*10;
}
test();
echo $num;
Output 100. The procedure is not difficult, just experience it yourself
The above has introduced the meaning and function of PHP global, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.