Monday, April 24, 2017

Modifying by reference

<?php
$x = 2;
echo "x is ".$x."<br/>";
$y = &$x;
$x = 3;
echo "assign x=" . $x . "<br/>";
echo "y is ".$y . "<br/>";
function modifyref(&$m) {
 $m = 5;
 echo $m . "<br/>";
}
echo "modify \$y ref to ";
modifyref($y);
echo "x is ". $x . "<br/>";
echo "y is ".$y;
?>
Output:
x is 2
assign x=3
y is 3
modify $y ref to 5
x is 5
y is 5

No comments:

Post a Comment

here docs

$x = <<<THE_END PHP stands for "PHP: Hypertext Preprocessor". The acronym "PHP" is therefore, usually referre...