: This article mainly introduces the static local variables of php. if you are interested in the PHP Tutorial, please refer to them. Static local variables can be used.
Global variablesIt is stored in the same area of the memory, but we leave the static local variable function and cannot access the variable. However, the variable is not destroyed, and its value is retained. When the function is called again, it can be accessed again. Note that:
1. when static local variables are declared, they cannot be Expressions. an error occurs in the expressions.
Static $ index = 1; static $ index = 5; // error
2. AssignmentStatic variablesExpressions are not allowed.
Static $ index = 1 + 1; // error
3. if we only declare a local variable that is not assigned a value, a 0 or empty string will be initialized for it by default. based on its type, determine whether it is a 0 or null string.
Example:
Dimensionality reduction of arrays (to one dimension)
ClassTest {publicfunctionreduce_arr ($ arr) {static $ temp = array (); // declares a static local variable foreach ($ arras $ key => $ val) {if (is_array ($ val) {$ this-> performance_arr ($ val);} else {$ temp [$ key] = $ val ;}} return $ temp ;}$ test = new Test (); $ arr = array ('0' => array ('good _ id' => 1 ), '1' => array ('good _ num' => 2), '2' => array ('good _ kids' => 2 )); var_dump ($ test-> performance_arr ($ arr); // A one-dimensional array is obtained.
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above describes the static local variables of php, including global variables and static variables. I hope my friends who are interested in the PHP Tutorial will be helpful.