Variables are "containers" for storing information. A variable can be used to hold values (eg. x=5) and expression (eg. z=x+y). PHP has no command for declaring a variable. We have to assign value to the PHP variable, while the creation of variable. If we want to create variable without assigning a value to it, then we assign NULL value to it. Generally in PHP, a variable does not need to be declared before adding a value to it.
Each variable has an area in which it exist, known as its scope PHP has four different variable scope:-
Local Scope:- A variable declared within a any PHP function is local and can only be accessed within that function.
<?php
$X=5 //Global
function myFun() {
echo $X //Local
}
myFun();
?>
The above script will not give any output, because the echo statement refers to the local scope.