top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between $name and $$name in PHP?

+2 votes
3,360 views
What is the difference between $name and $$name in PHP?
posted Jun 3, 2014 by Vrije Mani Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
$$name is a variable generates runtime
let's
$name='osama';
$$name ='feras';
now we have two variable the first one $name and the second one $osama
echo $osama ;
the output  is :  feras

$this is a special variable that can't be assigned .but you can declare $this variable using "$$"
let's
$name='this';
$$name ='feras';
echo $this;
the output  will be :  feras

2 Answers

+2 votes

Let's understand it with an example


$a="Please Test";
$xyz="a";
echo $$xyz

Output would be :
//Please Test

As $a is a simple variable with the value "Please Test" . $xyz is another variable consist of "a", which is actually a message type for $xyz but ultimately a variable declared previously.
Now $$xyz , going to check what insde the variable $xyz and as there is "a", then it will take a as the variable and print whatever("Please Test") in it.
Please vote up if you like the answer

answer Aug 13, 2014 by anonymous
0 votes

$name is variable where as
$$name is reference variable like $name=shikha
and $$name=singh so $sikha value is singh

answer Jun 4, 2014 by Deepak Negi
...