Passing And Returning References
Basically references are used to create alias for other variables.
For example
$var1 = &$var2;
Here $var1 is the alias of $var2
Passing And Returning References
Following example will show how to pass and return the references
function func1(&$i){
return ++$i;
}
$j = 6;
func1($j);
function &func2($i)
{
global $j;
$j = $i;
return $j;
}
$k = 8;
$l = & func2($k);
$j = 9;
echo $l;
function func1(&$i) - This line shows how to pass reference to a function
func1($j) - This line calls the above function. In the above function argument is named as &$i.So this is an alias for passing variable.so if we change $i, it will affect $j.
function &func2($i)- This is example of how to return reference to a function.
$l = & func2($k); - This line calls above function. In the above function we are returning a global variable $j.So $l is as alias for $j.if we change $l, it will affect $j and of-course reverse is also true.
