Home  >  Article  >  Backend Development  >  php tutorial PHP tutorial variable definition

php tutorial PHP tutorial variable definition

WBOY
WBOYOriginal
2016-07-29 08:41:021093browse

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 the 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 an underscore
$i site is = 'mansikka'; // Legal variable name; can use Chinese
?>


Naming rules for variables
The variable name 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).

The above introduces the PHP tutorial PHP tutorial variable definition, including the content of the PHP tutorial. I hope it will be helpful to friends who are interested in the PHP tutorial.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn