Home >>PHP Object Oriented >PHP Local Variables

PHP Local Variables

Local Variable

=> Local variables are always initialize inside the funtciob body. => Local variable cant work outside function body.

function add()
echo "sum of given no=".$sum;
function sub()
echo "subtraction of given no=".$sub;
Output Sum of given no = 300 Subtraction of given no = 300

Here define a variable $x and $y . Variable $x and $y has been defined inside add( ) function so these variables are not accessible outside the add( ) function. Now if you want to access local variable $x and $y inside the sub( ) function then declare it first then use.