What Is a Function?

You can think of a function as an input/output machine. This machine takes the raw
materials you feed it (input) and works with them to produce a product (output). A function
accepts values, processes them, and then performs an action (printing to the browser,
for example), returns a new value, or both.


Functions come in two flavors: those built in to the language and those you define
yourself. PHP has hundreds of built-in functions. Look at the following snippet for an
example of a function in use:

strtoupper(“Hello Web!”);


This example calls the strtoupper() function, passing it the string “Hello Web!”.
The function then goes about its business of changing the contents of the string to
uppercase letters. A function call consists of the function name (strtoupper in this
case) followed by parentheses.