i’d like to set up some global variables for storing several things.
i’ve tried it like this:
function init_web()
{
$webname = "myweb";
$web['webname'] = $webname;
$web['server_root'] = $_SERVER['DOCUMENT_ROOT']."/$webname/";
$web['lang']="en";
}
the problem is that i can’t access those variables inside of functions ..
i’ve tried using global $web; but didnt help.
what’s the trick to get it global?
thanks
While you’ll get the usual “global variables are bad” crying, here’s the basics:
basically, you had it, but hadn’t defined the variable outside the function. Just saying ‘global’ within the function won’t magically create one outside the function – it already has to exist before you try to “internalize” it to the function and change/access its contents.