Difference Between $var and $$var in PHP

PHP $$var uses the value of the variable whose name is the value of $var.

It means $$var is known as reference variable where as $var is normal variable.

<?php
 $name="Rajeev";
 $$name="Sanjeev";

 echo $name."<br/>";
 echo $$name."<br/>";
 echo $Rajeev;
?>

 Output:
  Rajeev
  Sanjeev
  Sanjeev

Leave a comment

Your email address will not be published. Required fields are marked *