4.5. Arguments

When declaring a function, you may declare arguments inside the parentheses, each separated by a comma. The arguments must be preceded by a dollar sign. They become variables inside the function. When the function is called, it expects values to be passed that will fill the arguments in the order declared.

Arguments, by default, copy the passed value into the local variable, otherwise known as pass-by-value. If the function argument is preceded by the & operator, the variable instead becomes an alias for the passed variable. This is commonly referred to as a variable reference. Changes made to referenced variables change the original. Chapter 2 contains a discussion of variable references.

To demonstrate this idea, imagine we wanted ...

Get Core PHP Programming, 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.