Variables defined within a PHP function live and die within the function. Variables defined outside the function, so-called global variables, are not visible inside a function. In this respect, PHP differs from most other languages. Global variables are accessible within a function if they are explicitly declared using the global keyword, as seen on lines 18 and 43. If a function's variable is to retain its value between function calls, the keyword static should start the variable declaration.
Static variables are useful as counters.
Well, there you have it, sports fans, our first PHP exploration. In the second article in this series we'll pick up where we left off and add field validation and introduce check boxes, radio buttons, and drop menus to our bag of form tricks. We'll also build a generic form handler. Where we go in the future is to a large part dependent on your feedback, so please let me know what you would like to see covered on these pages. Urb LeJeune is a 25-year programming veteran with over 10 years of Internet experience thrown in for good measure.