Passing by Reference

I am listing here a simple example to explain ‘passing by reference’ in PHP.

I hope it is helpful.


$a = 5;
echo 'A1->'.$a.'<br/>';
$b = 6;
$a =& $b;
echo 'A2->'.$a.'<br/>B1->'.$b.'<br/>';
global $var;
function foo(&$var)

echo 'A3->'.$a.'<br/>';
echo 'A4->'.$a.'<br/>Var->'.$var;


For further information kindly visit Passing by Reference

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top