More About Arguments

You’ve already seen how to pass arguments to functions, but there’s more to cover yet. In this section, you’ll look at a technique for giving your arguments default values and explore a method of passing variables by reference rather than by value. This means that the function is given an alias to the original value rather than a copy of it.

Setting Default Values for Arguments

PHP gives you a nifty feature to help build flexible functions. Until now, we’ve said that some functions demand one or more arguments. By making some arguments optional, you can render your functions a little less autocratic.

Listing 6.11 creates a useful little function that wraps a string in an HTML heading element. We want to give the user of ...

Get Sams Teach Yourself PHP in 24 Hours, Third 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.