Creating and Calling Your Own Functions

As you’ve already seen, PHP has a lot of built-in functions, addressing almost every need. More importantly, though, it has the capability for you to define and use your own functions for whatever purpose. The syntax for making your own function is

function function_name () {
   // Function code.
}

The name of your function can be any combination of letters, numbers, and the underscore, but it must begin with either a letter or the underscore. The main restriction is that you cannot use an existing function name for your function (print, echo, isset, and so on).

In PHP, as I mentioned in the first chapter, function names are case-insensitive (unlike variable names), so you could call that function using ...

Get PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition 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.