Variable variables in PHP are used to store values, such as numbers, text strings, or arrays. Once a variable is set, we can reuse it in the script. All variables in PHP start with the $ symbol, and the variable names are case sensitive. The correct way to set variables in PHP is: $ var_name = value; the PHP compiler often uses the variables in PHP.
Variables are used to store values, such as numbers, text strings, or arrays.
Once a variable is set, we can reuse it in the script.
All variables in PHP start with the $ symbol, and the variable names are case sensitive.
The correct method for setting variables in PHP is:
$ Var_name = Value;
PHP beginners often forget the $ symbol before the variable. In this case, the variable will be invalid.
Although variables do not need to be initialized in PHP, this is a good habit. Uninitialized variables have default values of their types-False, Zero, empty string or empty array.
<? PHP
$ VaR = ' PHP ' ;
$ VaR = ' Tutorial Network ' ;
Echo " $ VaR , $ VaR " ; // Output "PHP, tutorial network"
$4 site = ' Not yet ' ; // Illegal Change name; starting with a number
$ _ 4 site = ' Not yet ' ; // Valid variable name; starting with an underscore
$ I site is = ' Mansikka ' ; // Valid variable name; Chinese
?>
Variable naming rules
- The variable name must start with a letter or underscore.
- Variable names can only contain letters, numbers, and underscores.
- Variable names cannot contain spaces. If the variable name is composed of multiple words, it should be separated by underscores (for example, $ my_string) or begin with an uppercase letter (for example, $ mystring ).