O'Reilly logo

PHP Advanced for the World Wide Web: Visual QuickPro Guide by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

References and Functions

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required