Home >Backend Development >PHP Tutorial >Analysis on the scope of application of php global variables
Here variable $a will take effect in the include file b.inc. However, in user-defined functions, a local function scope will be introduced. Any variables used inside a function will be restricted to the local function scope by default.
This script will not produce any output, because the echo statement refers to a local version of the variable $a, and it is not assigned a value in this scope. You may notice that PHP’s global variables are a little different from those in C Global variables in PHP must be declared global (global keyword) when used in functions.
The above script will output: "3". |