PHP variables
A variable containing data or values. Variables are used to store and manipulate information within programs. Variables can have short names (such as a or b) or more descriptive names (name, age, total_result).
- PHP is a loosely typed language, so there is no need to declare data types for variables.
- Variables start with a $ symbol followed by the name of the variable
- Variable name must start with a letter or underscore variable name cannot start with a number
- Variable names can only contain alphanumeric characters and underscores (A-z, 0-9, and _).
- Variable names are case-sensitive ($user and $USER are two different variables).
- Assign a text value to a variable and enclose the value in quotes.
Example
<?php $str = "Welcome"; echo $str; ?>
Output
Welcome
Example
<?php $a= 10; $b=15; $c=$a+$b; echo $c; ?>
Output
25