: This article mainly introduces the php learning log-variable scope. if you are interested in the PHP Tutorial, refer to it. 1. access within the global function
Global variables
If the myTest function does not use global, it cannot be used.
PHP adds allGlobal variablesStored in a table named $ GLOBALS [Index.IndexSave the variable name. This array can be accessed inside the function or directly used to updateGlobal variables. For example, $ GLOBALS ['Y'] = $ GLOBALS ['x'] + $ GLOBALS ['Y']
2. Static when a function is completed, all its variables are usually deleted. However, sometimes you want a local variable not to be deleted.
Function myTest () {static $ x = 0; echo $ x; $ x ++;} myTest (); 012
Each time a function is called, the variable retains the value of the previous call of the function. This variable is still a local variable of the function.
The above introduces the php learning log-variable scope, including the global variables, and hopes to help those who are interested in the PHP Tutorial.