Can not access Global Vars inside a function?
Posted: Sat May 10, 2003 8:01 pm
Basically I am feeling out PHP for a couple projects. It's pretty simple. comming form ASP jscript to PHP. I kinda like some of the differences
However their is one thing that is annoying me and i hope this isn't the way it is. allow me to explain:
Why can I not use Global Var's inside a funtion?
<?
global $USState, $theString;
$USState = array();
$USState[name][0] ="AL(Alabama)";
$USState[name][1] ="AK(Alaska)";
$theString = "HIMOM";
// just a dummy function.
function dostuff()
{
$myCount = count($USState[name]);
printf('[global]$theString:'.$theString);
printf('[globalArray]$USState[name]'.$USState[name]);
}
dostuff();
?>
I hope I am doing something wrong.
However their is one thing that is annoying me and i hope this isn't the way it is. allow me to explain:
Why can I not use Global Var's inside a funtion?
<?
global $USState, $theString;
$USState = array();
$USState[name][0] ="AL(Alabama)";
$USState[name][1] ="AK(Alaska)";
$theString = "HIMOM";
// just a dummy function.
function dostuff()
{
$myCount = count($USState[name]);
printf('[global]$theString:'.$theString);
printf('[globalArray]$USState[name]'.$USState[name]);
}
dostuff();
?>
I hope I am doing something wrong.