Submitted by abitowhit on Sun, 08/25/2019 - 21:26
If you want to get the value of a global variable from within a function, you must define it as global within the function.
So if you have something like:
$x;
and want to use it within a function called GetX..
First define it as global
global $x;
$x="something";
Now within the function:
function GetX()
{
global $x;
if ($x=="something")
{
echo "Has ".$x;
}
else
{
echo "Sorry has ".$x;
}
}
If you change it outside of GetX function it should change within the function.
GetX();
$x="Nothing"; //changed it globally
GetX();