This section describes what is a function. A quick example is provided showing how to define and call a function.
What Is a Function?
A function is a definition of a block of statements.
The block of statements in a function will be executed only when the function is invoked.
PHP provides a long list of built-in (predefined) functions.
PHP supports user-defined functions - You define your own functions in PHP source code.
To learn how to use user-defined functions in PHP, we need to pay attentions in following areas:
1. How to define a function?
2. How to call a function to execute its statements?
3. How to pass input values into a function?
4. How to return a result from a function?
5. How to share variables with a function?
Here is a simple example script of defining a function, calling a function, passing data into a function, and returning result from a function: