"By default, variables passed to functions are passed by value. In other words, local copies of the values of the variables are made. You can change this behavior by creating a reference to your original variable. You can think of a reference as a signpost that points to a variable. In working with the reference, you are manipulating the value to which it points." (144)
This example is almost EXACTLY like the previous one, addfive.php, but the code adds one small ampersand - and what a difference it makes! Now, the argument is passed by reference, rather than by value (that's what the ampersand does). The effect is extraordinary - "the contents of the variable you pass ($orignum) are accessed by the argument variable and manipulated within the function, rather than just a copy of the variable's value (10). Any changes made to an argument in these cases will change the value of the original variable. You can pass an argument by reference by adding an ampersand to the argument name in the function definition..." (144).
<?php
function addFive(&$num) {
$num += 5;
}
$orignum = 10;
addFive($orignum);
echo $orignum;
?>