Variables in PHP:
Variables are the logical name given by the programmer which refers to a physical location in the memory. Variables are used for storing data or informations in computer memory.
Rules for constructing php variables:
- PHP variable starts with $ sign like $var1
- Variable name must start with alphabet or underscore after $.
Ex – $var (right)
- No special symbol other than the underscore can be used.
Ex – $var_1 (right)
- No comma or blank space can be used in variable name.
Ex – $var1 (right)
$var, 1 (wrong)
- It can contain digits but not as starting.
Ex - $var34 (right)
- variables are case sensitive, means $var and $VAR are different from each other.
PHP Variable Declaration:
php variable starts with a $ sign and followed by a user define name as follows:
Example: $var1, $var2,..............
PHP Variables Initialization:
php variables are initialized using an assignment operator “=” as follows
echo $var1.’ ’.$var; // here ‘.’ is a concatenation operation in php.
Note: echo is a php command, used to display or print messages in the output screen.
- \n is replaced by the newline character.
- \r is replaced by the carriage return character.
- \t is replaced by the tab character.
- \$ is replaced by a dollar sign itself($).
- \” is replaced by a single backslash(“).
- \\ is replaced by a single backslash(\).