Home >Backend Development >PHP Tutorial >The meaning and function of PHP global

The meaning and function of PHP global

WBOY
WBOYOriginal
2016-08-08 09:28:072306browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn