Understanding Variable Types in PHP: A Comprehensive Guide
Table of Content:
Declaring PHP variables
All variables in PHP start with a $ (dollar) sign followed by the name of the variable.
A valid variable name starts with a letter (A-Z, a-z) or underscore (_), followed by any number of letters, numbers, or underscores.
If a variable name is more than one word, it can be separated with an underscore (for example $employee_code instead of $employeecode).
'$' is a special variable that can not be assigned.
Example : Valid and invalid PHP variables
PHP variable name is case-sensitive
Consider the following example :
Output:
If you will rum the above code, you will get the following output.
Value of abc : Welcome Value of ABC :
Scope can be defined as the range of availability a variable has to the program in which it is declared. PHP variables can be one of four scope types ?
-
Local variables
-
Function parameters
-
Global variables
-
Static variables