Declare Variable in PHP ?
PHP Variable Deceleration : The Meaning of variable is not consistent or not having a fixed pattern,it is liable to change. In PHP way to store information in PHP program is by using a variable. All variables in PHP having prefix a dollar sign ($). The value of a variable is the value of its most recent assignment ,Variable name must follow rules for an identifier and should not start with Number.variable can store any type of information depends on the datatype of variable , it can store numeric , string, Boolean,Array, etc …
Eg.
$a= 10;
$name=\"Sourabh\";
$flag=\"True\";
$date=\"12/june/2016\";
Eligibility to be a Variable in php ?
- A PHP variable starts with the $ sign, followed by the name of the variable
- A PHP variable name must start with a letter or the underscore character
- A PHP variable name cannot start with a number
- A PHP variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
- PHP Variable names are case-sensitive ($php and $PHP are two different variables)
Scope of PHP Variables
The scope of a variable is the part of the script where the variable can be referenced/used.
PHP has three different variable scopes:
- Local
- Global
- Static