Variables in PHP
Variables are used to store values, such as numbers, text strings, or arrays.
Once a variable is set, we can use it repeatedly in the script.
All variables in PHP start with the $ symbol, and variable names are case-sensitive.
The correct way to set variables in PHP is:
$var_name = value; Beginners to PHP often forget the $ sign in front of the variable. If you do that, the variable will be invalid.
Although initializing variables is not required in PHP, it is a good practice. Uninitialized variables have a default value of their type - FALSE, zero, the empty string, or the empty array.
Copy code The code is as follows:
$var = 'PHP';
$ Var = 'Tutorial Network';
echo "$var, $Var"; // Output "PHP, Tutorial Network"
$4site = 'not yet'; // Illegal name change; starts with a number
$_4site = 'not yet'; // Legal variable name; starts with underscore
$i site is = 'mansikka'; // Legal variable name; can be in Chinese
?>
Naming rules for variables
Variable names must start with a letter or underscore "_".
Variable names can only contain alphanumeric characters and underscores.
Variable names cannot contain spaces. If the variable name consists of multiple words, they should be separated by underscores (such as $my_string) or start with a capital letter (such as $myString).
http://www.bkjia.com/PHPjc/320761.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320761.htmlTechArticleVariables in PHP Variables are used to store values, such as numbers, text strings, or arrays. Once a variable is set, we can use it repeatedly in the script. All variables in PHP...