Can some one help me out by explaining global variable and how to set them?
| SitePoint Sponsor |

Can some one help me out by explaining global variable and how to set them?
jmulder[THE MENTOR]'s nice guy online!
Rig: AMD Athlon 800mhz; 384mb SDRam; 32mb nVidia @ 1024x768; ie 6; Windows ME; 15 gig; Cd-RW


The reason you would declare something global is so you could use that variable from with a function without passing that variable, otherwise the variable is outside the scope of the function.
Example:
But if you put global in front of $var within the function, you are referencing the same variable as declared outside the functionPHP Code:$var = 5;
function foo()
{
echo $var; // this is a different $var than outside the function
}
PHP Code:$var = 5;
function foo()
{
global $var
echo $var; // prints 5
}

thanks guy(gal)
i'll try something out
jmulder[THE MENTOR]'s nice guy online!
Rig: AMD Athlon 800mhz; 384mb SDRam; 32mb nVidia @ 1024x768; ie 6; Windows ME; 15 gig; Cd-RW
Bookmarks