A variable is a container used to temporarily store values. These values can be numbers, texts, or much more complex data.
PHP has eight variables.
There are four scalar (single value) types: string (character), integer, floating point (decimal), and Boolean (TRUE or FALSE );
Two non-standard (multi-value) types-arrays, objects, and resources (you will see it when interacting with the database) and NULL (it is a special type that does not have any value ).
========================================================== ==========================================
PHP syntax rules:
1. The variable name, also known as its identifier, must begin with the dollar sign ($), for example, $ name.
2. A variable name can contain a combination of letters, numbers, and underscores, for example, $ my_report1.
3. The first character after the dollar sign must be a letter or underscore (not a number ).
4. Variable names in PHP are case sensitive. This is a very important rule. This means that $ name and $ Name are completely different variables.
FAQ:
First, you can use the equal sign (=) (also known as the value assignment operator) to assign values to variables.
Second, variables can be printed without quotation marks; or variables can be printed in double quotation marks; but variables cannot be printed in single quotation marks.
<? Phpecho $ name; // print the variable echo "Hello, $ name" without quotation marks; // print the variable echo 'hello, $ name' in double quotation marks '; // print the variable in single quotes [an error will be reported]?>
========================================================== ==========================================
[1] when creating a variable, the most important consideration is to use a consistent naming mode. Some programmers prefer to use variable names with lower-case letters and underlines to separate words ($ first_name). Some programmers prefer to use uppercase letters, for example: $ FirstName (camper ).