Passing by Reference in PHP : Variable Reference « Language Basics « PHP






Passing by Reference in PHP

 
<?php

    function reference_test($var, &$result, &$result2) {

        $result = "This is return value #1";
        $result2 = "You entered $var as your parameter";

        return 42;

    }

    $res = reference_test(10, &$res1, &$res2);

    echo "The value of \$res is '$res'<BR>";
    echo "The value of \$res1 is '$res1'<BR>";
    echo "The value of \$res2 is '$res2'<BR>";

?>
  
  








Related examples in the same category

1.$b is assigned a copy of $a, and in the second part, $b is assigned a reference to $a.
2.& operator creates a reference
3.Create a reference to a variable with the name of the constant's value.
4.Only named variables may be assigned by reference.
5.Passing arrays by reference