PHP variables do not need to be declared before using them. However, it is considered better programming practice if variables are first declared.
PHP variables do not need to be initialized before using them, however it is also considered good programming practice to first initialize a variable.
Naming PHP Variables
Variable names are case sensitive. Valid variable names can be composed of letters A to Z, a to z, numbers 0 to 9 and the underscore _, but must keep to the following rules.
- Variable names must start with a dollar sign $.
- At least one alphabet letter or an underscore must follow the dollar sign.
- Numbers 0 to 9 can be used in the variable name, but a number may not immediately follow the dollar sign.
PHP Variables Reference Manual
See the PHP language reference on variables in the PHP manual for more information on PHP variables.
PHP Data Types
The basic types in PHP that can be assigned to a variable are integer numbers, floating point numbers, booleans, strings, arrays and objects. For a complete list of all PHP data types and an explanation of each, see PHP types in the PHP manual.
- Variable names must start with a letter, underscore or dollar sign.
- Variable names may not start with a number (0 to 9).