First, local variables
Definition: A variable that is declared inside a function and can only be called inside a function.
Note: Parameters are also one of the local variables.
Demo1:
1 function demo1 () {
2 $age = 10;
5;
4
5 echo $age; Undefined Local variables can no longer be called outside the function
Second, global variables
Definition: Declared outside the function, you can use the Global keyword call inside the function. (Note order)
Demo2:
$name = "Linwu";
function Demo2 () {
Global $name;
Echo $name;
}
Demo2 ();
It is important to note, however, that the declaration of a global variable must precede a function call.
DEMO3:
function Demo2 () {
Global $name;
Echo $name;
}
$name = "Linwu";//Output Linwu
Demo2 ();
Demo4:
function Demo2 () {
Global $name;
Echo $name;
}
Demo2 ();//Cannot output normally
$name = "Linwu";
Manuscripts: Seven Stars interconnection www2.qixoo.com
PHP Local variables and global variables