A variable is a way to store information in may program and scripting languages. In PHP, variables can store things such as strings, integers, floats, boolean, or other objects.
To definite and initialize a variable in PHP, you simply use the following form within your code:
1 |
$variable_name = value;
|
When creating a new variable in PHP, you must follow the simple naming conventions below:
- Variables must start with a letter or underscore ("_").
- Variables with more than one word should be separated with underscores (i.e. $new_variable) or distinguished with capitalization (i.e. $newVariable).
- Variables may only named with alpha-numeric characters and underscores (i.e. $new_variable01).
- Variables should NOT contain spaces.
A few notes about PHP variables:
- You must include the dollar sign at the beginning of the variable in order for the PHP to parse it correctly.
- Variables do not be to be declared before they are initialized.
You must include the dollar sign at the beginning of the variable in order for PHP to parse it correctly.




