Let me explain to those who are new to the industry the use of global variables, "global variables". The two words "global" in this noun already tell us that this variable can be used everywhere. Let's look at an example first:
Copy code The code is as follows:
$a = 1;
$b = 2;
function Sum()
{
global $a, $b; //Declared as a global variable inside
$b = $a + $b;
}
Sum();
echo $b;
?>
Result: 3
If there is no global variable global, the values of $a and $b cannot be obtained in the method, so in the method If you want to use an external variable, you need to declare the variable as a global variable first, so that it can be used. It is very convenient.
http://www.bkjia.com/PHPjc/323312.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323312.htmlTechArticleLet me explain the use of global variables to those who are new to the industry, "global variables", in this noun The word global already tells us that this variable can be used everywhere, let’s look first...