Php global variable range analysis. Copy the code as follows :? Php $ a1; includeb. inc ;? The variable $ a will take effect in the included file B. inc. However, in a user-defined function
The code is as follows:
$ A = 1;
Include 'B. Inc ';
?>
The variable $ a will take effect in the included file B. inc. However, in user-defined functions, a local function range will be introduced. By default, any variable used in a function is limited to a local function.
The code is 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 references a local version of variable $ a and is not assigned a value within this range. You may notice that the global variables in PHP are a little different from those in C.
Global variables in PHP must be declared as global when used in functions)
The code is as follows:
$ A = 1;
$ B = 2;
Function Sum ()
{
Global $ a, $ B;
$ B = $ a + $ B;
}
Sum ();
Echo $ B;
?>
The output of the above script is "3 ".
The http://www.bkjia.com/PHPjc/320427.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/320427.htmlTechArticle code is as follows :? Php $ a = 1; include 'B. Inc ';? The variable $ a will take effect in the included file B. inc. However, in a user-defined function, the range of a local function will be...