Functions can expect, by declaring them in the function definition, an arbitrary number of arguments. There are two different ways to pass parameters to a function. The first, and more common, is by value. The other is by reference.
In most cases, you pass parameters by value. The argument is any valid expression. That expression is evaluated, and the resulting value is assigned to the appropriate variable in the function. In all of the examples so far, we’ve been passing arguments by value.
Passing by reference allows you to override the normal scoping
rules and give a function direct access to a variable. To be passed by reference, the argument must be a variable;
you indicate that a particular argument of a function will be passed by
reference by preceding the variable name in the parameter list with an
&). Example 3-4 revisits our
doubler() function with a slight
Because the function’s
parameter is passed by reference, the actual value of
$a, rather than a copy of that value, is
modified by the function. Before, we had to
return the doubled value, but now we change
the caller’s variable to be the doubled value.
Here’s another place where a function contains side effects: since
we passed the variable
doubler() by reference, the value of
$a is at the mercy of ...