In PHP, a variable begins with the $ sign, followed by the variable name.
|
In the example above, the variable $x will store the value 5, while the variable $y will hold the value “John”.
Note: When assigning a text value to a variable, enclose the value in quotes.
Note: Unlike many other programming languages, PHP does not require a specific command to declare a variable; it is created as soon as you assign a value to it.
| Consider variables as containers for holding data. |
A variable can have a short name (like $x and $y) or a more descriptive name (like $age, $carname, or $total_volume).
Here are the rules for PHP variables:
$ sign, followed by the variable name.$age and $AGE are treated as distinct variables).| Keep in mind that PHP variable names are case-sensitive! |