Changes

Jump to: navigation, search

PHP Functions

678 bytes removed, 14:58, 10 August 2009
Returning Values by Reference
?>
</pre>
 
Note that in the above example we have used variable names $arg1 and $arg2 for the function arguments and ''$var1'' and ''$var2'' for the script that calls the 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''.
== Functions and Variable Scope ==

Navigation menu