Declaring a Function

When you declare a function, you start with the function statement. Next comes a name for your function. Inside the parentheses is a list of arguments separated by commas. You may choose to have no arguments. Figure 4-1 shows you the form of a function declaration.

Figure 4-1. Declaring a function.

In other languages, including older versions of PHP, you must declare a function above any call to it. This is not true of PHP 4. You may put a function declaration after calls made to it. When you call a function, you write its name followed by parentheses, even if there are no arguments to pass.

Functions allow you to put ...

Get Core PHP Programming: Using PHP to Build Dynamic Web Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.