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, please visit our PHP Reference.
In this chapter we will show you how to create your own functions.
To keep the script from being executed when the page loads, you can put it into a function.
A function will be executed by a call to the function.
You may call a function from anywhere within a page.
PHP function guidelines:
A simple function that writes my name when it is called:
Output:
To add more functionality to a function, we can add parameters. A parameter is just like a variable.
Parameters are specified after the function name, inside the parentheses.
The Below example will write different first names, but equal last name:
The Below function has two parameters:
To let a function return a value, use the return statement.
Your Query was successfully sent!