O'Reilly logo

PHP 7 Quick Scripting Reference, Second Edition 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

© Mikael Olsson 2016

Mikael Olsson, PHP 7 Quick Scripting Reference, 10.1007/978-1-4842-1922-5_8

8. Functions

Mikael Olsson

(1)Hammarland, Finland

Functions are reusable code blocks that only execute when called. They allow the code to be divided into smaller parts that are easier to understand and reuse.

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 convention1 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, ...

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