User-Defined Functions

   

In addition to PHP's built-in functions, you can create your own functions. Remember that if you want to use variables that exist outside of the function, then you must declare them as global variables or assign them as arguments to the function itself.

 function check_age($age) {      if ($age > 21) {         return 1;     } else {         return 0;     } } //usage: if(check_age($age)) {     echo "You may enter!"; } else {     echo "Access Not Allowed!";     exit; } 

The function would be called from within your script at the appropriate time, using the following syntax:

 $age = 10;  check_age($age); // prints "Access Not Allowed!" to the screen 

   
Top


Advanced PHP for Web Professionals
Advanced PHP for Web Professionals
ISBN: 0130085391
EAN: 2147483647
Year: 2005
Pages: 92

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net