O'Reilly logo

PHP Quick Scripting Reference by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 8

image

Functions

A function is a reusable code block that will only execute when called.

Defining functions

To create a function the function keyword is used followed by a name, a set of parentheses and a code block. The naming convention for functions is the same as for variables – to use a descriptive name with each word initially capitalized, except for the first one.

function myFunc(){  echo "Hello World";}

A function code block can contain any valid PHP code, including other function definitions.

Calling functions

Once defined a function can be called (invoked) from anywhere on the page, by typing its name followed by a set of parenthesis. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required