Php Basics-instance: What is the use and difference between global and static ??? FunctiontestGloabl (){?????? Global $ testGloabl ;?????? $ TestGloabl = 2 ;?????? $ TestGloabl ++ ;????}???? T php Basics-instance: use and difference of global and static
?? ? Function testGloabl (){
??? ??? Global $ testGloabl;
??? ??? $ TestGloabl = 2;
??? ??? $ TestGloabl ++;
???? }
???? TestGloabl ();
???? Echo $ testGloabl. "|". $ GLOBALS ['testgloabl '];
????
???? Function testStatic (){
??? ??? Static $ testStatic = 2;
??? ??? $ TestStatic ++;
???? }
??? TestStatic ();
??? Echo $ testStatic; // if the variable uses the static keyword, $ testStatic is not defined during external function access;
?
Note:
1. use the global keyword. when the function where the keyword is located is called, it will be accessible anywhere in the current script.
2. use the static keyword. when the keyword is accessed in the function, it cannot be accessed outside the function.
In common: global? Static allows positioning variables to point to the same memory area.