Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

Chapter 7. Function Reference

This chapter lists many of the most commonly used functions in PHP. Other functions are grouped together according to their topic, throughout this book.

Calling a function in PHP can be as simple as printing the name of a function with two parentheses, "()", after it. However, many functions require you to give them input to work on, called parameters, which you send inside the parentheses. On top of that, nearly all functions have a return value, which is the result that the function sends back to your script. These return values can often be ignored, but most of the time, you will want to store them in a variable for later use:

    $string_length = strlen($mystring);

You can also use these return values as parameters to other functions, like this:

    func1(func2(func3(), func4()));

Although most parameters are required, some are optional and don't need to be supplied. When optional parameters are omitted, PHP will assume a default value, which is usually good enough.

When you pass a parameter to a function, PHP copies it and uses that copy inside the function. This process is known as pass by value , because it is the value that is sent into the function rather than the variable. This means that when you pass variables to a function, it can change its copies of them however it likes, without affecting the original variables. To change this behavior, you can opt to pass by reference, which works in the same way as reference assigning for variables—PHP passes ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page