Log in

View Full Version : $GLOBALS in a function



fileserverdirect
10-19-2007, 10:28 PM
Hello,
I am writing alot of functions for my website in php, and in almost every one, It requires a variable outside of the functions. So thats why the invented $GLOBALS. But, It gets to be a pain writing out $my_var = $GLOBALS['myvar']; for every stupid function, especially when there's over 20 that I need. And there is no way will I put all 20 variables in the calling perenthese.
I tried a for-loop but every time I attempt, I always get: Phrase Error: da-da-da-da-da... Can someone please make a simple for loop that changes all globals into varables. Thanks in advance.
~FSD

djr33
10-19-2007, 10:32 PM
foreach ($GLOBALS as $k=>$g) {
$$k = $g;
}

to return them:
foreach ($GLOBALS as $k=>$g) {
$tempglobals[$k] = $$k;
}
$GLOBALS = $tempglobals;