Home > Article > Backend Development > Do php variables need to be defined?
Do php variables need to be defined?
php variables need to be defined. Variables are containers for storing information.
PHP variable rules:
Variables start with a $ symbol, followed by the name of the variable
Variable names must start with a letter or an underscore
Variable names cannot begin with a number
Variable names can only contain alphanumeric characters and underscores (A-z, 0-9, and _)
Variable names are case-sensitive ($y and $Y are two different variables)
Note: PHP variable names are case-sensitive!
Creating PHP variables
PHP does not have a command to create variables.
The variable will be created when it is assigned a value for the first time:
Example
<?php $txt="Hello world!"; $x=5; $y=10.5; ?>
After the above statement is executed, the variable txt will save the value Hello world!, and the variable x will save the value 5, the variable y will hold the value 10.5.
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of Do php variables need to be defined?. For more information, please follow other related articles on the PHP Chinese website!