Copy the Code code as follows:
$a = 1;
Include ' B.inc ';
?>
Here the variable $a will take effect in the include file B.inc. However, in a user-defined function, a local function scope is introduced. Any variables that are used inside the function will be limited to the local function in the default context.
Copy the Code code as follows:
$a = 1; /* Global scope */
function Test ()
{
echo $a; /* Reference to local scope variable */
}
Test ();
?>
This script does not have any output, because the Echo statement refers to a local version of the variable $a, and within that range, it is not assigned a value. You may notice that PHP's global variables are a little different from the C language.
Global variables must be declared global when used in a function in PHP
Copy the Code code as follows:
$a = 1;
$b = 2;
function Sum ()
{
Global $a, $b;
$b = $a + $b;
}
Sum ();
Echo $b;
?>
The output of the above script will be "3".
The above describes the global variable PHP global variable range analysis, including the contents of the global variables, I hope that the PHP tutorial interested in a friend helpful.