Changes

PHP Functions

737 bytes added, 15:01, 10 August 2009
Passing Parameters by Reference
After var1 = 20, var2 = 30
</pre>
 
 
Note that in the above examples we have used variable names $arg1 and $arg2 for the function arguments and ''$var1'' and ''$var2'' for the script fragment that calls the function. It is also valid to use the same names for both the variables and the arguments. For example, the following is valid syntax:
 
<pre>
<?php
function addNumbers (&$var1, &$var2)
{
$var1 += 10;
$var2 += 10;
return $var1 + $var2;
}
 
$var1 = 10;
$var2 = 20;
 
echo "Before var1 = $var1, var2 = $var2 <br>";
addNumbers ($var1, $var2);
echo "After var1 = $var1, var2 = $var2 <br>";
?>
</pre>
 
The above re-use of variable names is possible because of something called ''variable scope'', a topic that will be covered later in this chapter.
== Returning Values by Reference ==