1

Possible Duplicate:
what does $$ mean in PHP?

what is the different between $thisvariable and $$thisvariable. as you notice, the first variable has one dollar sign while the second got two dollar signs.

Community
  • 1
  • 1
justjoe
  • 5,144
  • 9
  • 41
  • 64
  • duplicate of [what does $$ mean in PHP?](http://stackoverflow.com/questions/2715654/what-does-mean-in-php) – outis Oct 01 '10 at 03:32
  • 1
    The PHP manual is always a good place to start. :) http://php.net/manual/en/language.variables.variable.php – dee-see Oct 04 '10 at 03:01

2 Answers2

13

$variable is a variable and $$variable is a variable variables,

$my_name = "anthony"; // variable $my_name 
echo $my_name; // outputs "anthony"

$a_var = "my_name"; // assigning literal to variable $a_var
echo $$a_var; // outputs "anthony"

It may be a bit confusing, so let's break down that echo call,

$($a_var)  
   -> $(my_name) 
       -> $my_name = "anthony"

Please note that the above may not be what happens behind the scenes of the PHP interpreter, but it serves strictly as an illustration.

Hope this helps.

Anthony Forloney
  • 84,001
  • 14
  • 111
  • 112
4

$thisvariable is a variable named $thisvariable:

$thisvariable = 'Hello';
print $thisvariable; // prints Hello

$$thisvariable is a variable variable:

$thisvariable = 'Hello';
$Hello = 'Greetings';
print $$thisvariable; // prints Greetings ($$thisvariable is equivalent to $Hello)

For the most part you should avoid using variable variables. It makes the code harder to understand and debug. When I see it it's a red flag that there's some bad design.

NullUserException
  • 77,975
  • 25
  • 199
  • 226