PHP $ and $$ Variables

PHP $var variable is a normal variable that stores any value. PHP $$var variable is a reference variable that stores the value of$var inside it. Let us take an example. Example 1

<?php
$x = "Hello";  // normal variable
$$x = 100;  // reference variable
echo $x."<br/>";  
echo $$x."<br/>";
?>
Output Hello 100 100 Example 2
<?php
$name="Rasmus";  // normal variable
$$name="Rasmus"; // reference variable
echo $name."<br/>";
echo $$name."<br/>";
echo $Rasmus;
?>
Output : Rasmus Rasmus Rasmus



ADVERTISEMENT
ADVERTISEMENT