Passing Variable Arguments by VALUE to Functions

Chapter 7 #144 - Martha's CIS 52

ASSIGNMENT/EXPLANATION

In this example, the $addFive variable accepts a single numeric value, and then adds 5 to it. A value is then added to the $orignum variable, and then this value is passed to the $addFive() function. What this means is that "A copy of the contents of $orignum is stored in the variable $num. Although $num is cremented by 5, this has no effect on the value of $orignum. When $orignum is printed, you find that its value is still 10." (144) This situation can be compared to addfive2.php, where an argument is passed to a function by reference.

Exercise

10

CODE

<?php 
function addFive($num) {
$num += 5;
}
$orignum = 10;
addFive($orignum);
echo $orignum;
?>