The real power of PHP comes from its functions.
In PHP, there are more than 700 built-in functions.
For a complete reference and examples of the built-in functions
in this chapter we will show you how to create your own functions.
To keep the browser from executing a script when the page loads, you can put your script into a function.
A function will be executed by a call to the function.
You may call a function from anywhere within a page.
A function will be executed by a call to the function.
function functionName()
{
code to be executed;
}
PHP function guidelines:
A simple function that writes my name when it is called:
| <html> <body> <?php echo “My name is “; </body> |
Output:
My name is Kai Jim Refsnes
PHP Functions – Return valuesTo let a function return a value, use the return statement. Example<html> <?php echo “1 + 16 = ” . add(1,16); </body> Output:
|