Variables are “containers” for storing information, which have a user-defined name. Using variables we can store some information and use later within the program.
In PHP we don’t need to specify the Datatype of a variable it automatically converts its type.
Rules for PHP variables –
- A variable starts with the $ sign, followed by the name of the variable.
- A variable name must start with a letter or the underscore character.
- A variable name cannot start with a number.
- A variable name can only contain alphanumeric, character and underscores ( A-Z,0-9 and _ ).
- Variable names are case sensitive ( $x and $X ) are two different variables.
Creating (Declaring) PHP variables –
- PHP has no command for declaring a variable.
- A variable is created the moment you first assign a value to it.
<?php $text = "Hello World"; echo $text; ?>