Variables in the PHP language
The PHP data storage unit is a variable and constant that stores various types of data. PHP is a It is a weakly typed language. There is no need to declare variables before using them. Variables are created when assigning values. This reason makes PHP syntax very different from C language and Java (strongly typed languages). (Recommended learning: PHP programming from entry to proficiency)
Declaration and attention of PHP variables
You must use a dollar sign when declaring variables in PHP "$" is followed by the variable name, and then the assignment operation (=) is used to assign a value to a variable.
There is a certain scope of use after PHP variables are declared. Most PHP variables are not declared in functions. Only a separate range from the declaration point to the end of the file is used. This separate range can be used in all PHP on a page. mode used.
also includes include and require import files. During the variable usage period, you can use unset() to release the specified variable, use isset() to check whether the variable is set, and use isempty() to check whether the variable is empty.
php variable naming rules
1. Case sensitive
$A and $a$ are two different variables, (system built-in structure and keywords, user-defined class and function names are case-sensitive).
2. The variable starts with the $ symbol, followed by the name of the variable.
3. Variable names must start with letters or underscores and cannot start with numbers.
4. Variable names can only contain alphanumeric characters and underscores (A-z, 0-9 and _)
If the variable is composed of letters, all lowercase characters are usually used as the variable name. ; If the variable is composed of multiple characters, use all lowercase letters for the first letter, and capitalize each subsequent letter.
The above is the detailed content of How to name variables in php. For more information, please follow other related articles on the PHP Chinese website!