[Previous] [Contents] [Next]


How Variables Are Passed to Functions

By default, variables are passed to functions by value, not by reference. The following example:

function doublevalue($var)
{
  $var = $var * 2;
}

$variable = 5;
doublevalue($variable);
echo "\$variable is: $variable";

has the output:

$variable is: 5

The parameter $variable that is passed to the function doublevalue( ) isn't changed by the function. What actually happens is that the value 5 is passed to the function, doubled to be 10, and the result lost forever! The value is passed to the function, not the variable itself.


[Previous] [Contents] [Next]