December 2001
Intermediate to advanced
520 pages
13h 42m
English
As a default, functions receive arguments on a call-by-value basis. This means that a function receives the value of a variable, not the actual variable itself. To alter the value of a variable within a function, you need to either use the global statement or pass the variable by reference.
Here's an example of how functions normally operate:
function change_value ($variable) {
$variable++;
echo $variable;
}
$variable = 1;
change_value ($variable);
The echo statement will print a 2, but the value of $variable is still 1 (remember that $variable within the function is not the same as $variable outside of it, despite the common name). However, if you were to pass $variable to the function as a reference, the value of ...
Read now
Unlock full access