I was just working on implementing this credit card validation script . I had been working with a similar version that was on devarticles.com and the script they have there did NOT work. (The one I linked DOES work!) In any case, I noticed in the one that didn't work, the author was declaring a lot of variables as "global" (this wasn't the reason why the script wasn't working), but it made me wonder when you needed to declare variables as global and when you didn't. A little search on Google, and I found this explanation here: (I am quoting them verbatim – on a side note, for those of you who are interested in a php site for newbies, phpbeginner.com looked pretty good!)
…. Here we declare $variable1 to be 'global'. When a variable is not declared as global inside a function, PHP basically goes 'ok, since this is NOT a global variable we'll make a "new"$variable1 JUST for use INSIDE this function. And when the function is finished executing, we can jut throw that variable away! This approach is GREAT when we want to use variables as temporary things, but not when we want what we're doing to affect the rest of our script's 'world'. When we declare a variable as 'global' it makes the PUBLIC version of that variable available to the function, and any changes we make to are permanent! Also of importance: if you declare a variable as global inside a function–and the variable did not exist in the script beforehand–it does now, so be careful.
One last note before I get on with things: if you declare a variable to be 'global' inside one function, then it is global–but only for that function, you must re-declare it as 'global' in each function that you want to work with it globally.