PHP Variables
A variable is something that can be changed. It is used to store a value that may be changed. In php variable is starting with the symbol of $.
Declare a variable in php:
$variable_name = value;
Example: $web=5;
![]() |
Note: Variables must be starts with $. |
<?php $a="good morning!"; //$variable_name = value; $b=55; ?>
Here $a and $b are variables. Values are 55 and ‘good morning’.
Naming Conventions of variables:
Some Rules are set for declaring a name for variable. These rules are Naming Conventional rules.
![]() |
Variable name must start with a letter or an underscore "_". |
![]() |
A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ ). |
![]() |
A variable name should not contain spaces. If a variable name is more than one word, it should be separated with underscore ($my_string), or with capitalization ($myString). |
