(3) PHP study Notes-basic syntax: variable creation
PHP does not have a command to create variables. it is created when the first value is assigned and automatically converted to the correct data type.
PHP naming rules:
A variable starts with $, followed by the variable name.
The variable name must start with an underscore (_) and a letter.
Variable names can only contain letters and underscores. (A-z, 0-9, and _)
Variable names are case sensitive ($ S and $ s are not the same variable)
PHP variable scope
Local)
Global)
Static)
LOCAL scope and Global scope
Variables declared outside the function have a Global scope and can only be accessed outside the function.
Variables declared in the function have LOCAL scopes and can only be accessed within the function.
Let's give a second example to increase your understanding.
"; // Line feed echo $ B; // The value is 2-no change, or what should a person do. Echo"
";}Test (); echo $ a; // The value is 1, unchanged --- time flow, the goddess was abandoned by Gao fushuai or a person echo"
"; Echo $ B; // variable B in the external output function of the function. the output is empty. The goddess is discarded and comes back to loser, loser said that when I was dumb, the children in my stomach were not mine, so the output was empty. Echo"
"; Echo" the above line is empty! "?>
Global keywords
In combination with the example above, it is used to make loser (local variable B) a magic weapon to attack the goddess (global variable a)-become Gao fushuai
Used to access global variables in a function
"; Echo $ B; // The value is 2 -- the output variable B outside the function is not empty. -- how can we make it if Gao fushuai and goddess want to?>
Static keywords
Generally speaking, after the function is executed, all local variables will be deleted-the goddess will get rid of Gao fushuai.
However, sometimes I do not need to delete a local variable-or even make it easier to live together.
You can try it out of static...