O'Reilly logo

PHP 5 Power Programming by Derick Rethans, Stig Sæther Bakken, Andi Gutmans

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

2.8. Functions

A function in PHP can be built-in or user-defined; however, they are both called the same way.

The general form of a function call is

func(arg1,arg2,...)

The number of arguments varies from one function to another. Each argument can be any valid expression, including other function calls.

Here is a simple example of a predefined function:

$length = strlen("John");

strlen is a standard PHP function that returns the length of a string. Therefore, $length is assigned the length of the string "John": four.

Here's an example of a function call being used as a function argument:

$length = strlen(strlen("John"));

You probably already guessed the result of this example. First, the inner strlen("John") is executed, which results in ...

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