Reason of ampersand (&) sign before a variable name in PHP
<?php
$number = 1;
$pointer = &$number;
echo $number."<br/>"; // outputs 1
echo $pointer."<br/>"; // outputs 1
$pointer = 2;
echo $number."<br/>"; // outputs 2
echo $pointer."<br/>"; // outputs 2
?>
$number = 1;
$pointer = &$number;
echo $number."<br/>"; // outputs 1
echo $pointer."<br/>"; // outputs 1
$pointer = 2;
echo $number."<br/>"; // outputs 2
echo $pointer."<br/>"; // outputs 2
?>
Comments
Post a Comment