search
top

Passing by Reference

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

I hope it is helpful.

<?php

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

$a=5;
echo 'A3->'.$a.'<br/>';
foo($a);
echo 'A4->'.$a.'<br/>Var->'.$var;

?>

For further information kindly visit Passing by Reference

Leave a Reply

top