The purpose of the "global" statement within a function is to let PHP know 
that the usage of a var name INSIDE that function is not meant to create a 
NEW variable, but instead, to reference the other (global) variable being 
used (and perhaps already defined) in your main script.

Basically it works like this:

You can:
- create vars in the main script usable in that script's main body outside 
of any functions

- create vars to be used entirely and only within any functions in your 

-reference vars from the main script within a specific function by 
referencing them with a "global $xxx,$yyy,$zzz" statement at the top of your 

And Finally You Can:

- create $_SESSION['xxx'] var that can be seen anywhere in your 
application(s) during the life of the current session.  Close the browser or 
fail to do a "session_start()" in a script and you can't see them, but who 
would do that?

I'm sure someone will have something else to add, but I think this is all 
the knowledge one needs to accomplish most php programming. 

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to