Php variables declaration
A Php variables begin with $ dollar sign followed by the variable name. The rules are same as that of C++
- Variable name can begin with a letter or an underscore ‘_’ .
- Variable name can be combination of letter, digits, or underscores.
- Some valid examples are-
- Variable are case sensitive i-e,
have no relation to one another.
Php variable assignment
The simple type of assignment where variables are given values that are integer, string etc.
Valid examples include:
Php4 introduced the ability to assign value by reference which means, the variable will hold content assigned to some other variable to which it is referenced.
$value2=& $value1 //both equal to Hello
Php variables can have one of four scope types:
- Local Variable:Variable declared inside a function is called local. It can be referenced only inside the function.
- Global Variable:Variable that can be accessed in any part of the program. They are modified using global valuables.
- Function parameter:Parameters are arguments accepted by the function.Although these arguments take value from outside, they are no longer accessible after the function exits.
- Static Variable:These variable do not lose their values when the function exsits.