Changes

PHP Functions

550 bytes added, 20:29, 31 May 2007
Passing Parameters By Reference
Before var1 = 10, var2 = 20
After var1 = 20, var2 = 30
</pre>
 
== Returning Values By Reference ==
 
In addition to passing arguments into a PHP function by reference, it is also possible to return a result by reference. To achieve this the name must be prefixed with the '&' character in the function defintion and, also at the point at which it is called. In the following example the ''addNumber()'' function returns the result by reference:
 
<pre>
<?php
function &addNumbers ($val1, $val2)
{
$val1 += 10;
$val2 += 10;
return $val1 + $val2;
}
 
$myVar = &addNumbers (20, 10);
 
?>
</pre>