GilesGuthrie
Staff Emeritus
- 11,038
- Edinburgh, UK
- CMDRTheDarkLord
Does anyone here code using global variables? I'm having real difficulty with them. Like they're not working!
If I do the following:
I get:
Which isn't good. It's not life threatening, because it just means I have to pass the variable all the time, which is a pain. Am I being dense here?
If I do the following:
PHP:
global $year;
$year = 2003;
function printyear()
{
echo "From inside the function: ".$year;
}
echo "From outside the function: ".$year;
I get:
From inside the function: 0
From outside the function: 2003
Which isn't good. It's not life threatening, because it just means I have to pass the variable all the time, which is a pain. Am I being dense here?