Understanding Local Variables in PHP: Usage and Best Practices
☰Fullscreen
Table of Content:
A variable declared in a function is considered local; that is, it can be referenced solely in that function. Any assignment outside of that function will be considered to be an entirely different variable from the one contained in the function ?
Example:
"; } assignValue(); print "\$x outside of function is $x.
"; ?>
Output:
This will produce the following result -
$x inside function is 0. $x outside of function is 4.