1

Possible Duplicate:
What does $$ mean in PHP?
Double dollar sign php

What is $$ in php. This question is asked in a recent interview for a web developer position. Thanks in advance!

Community
  • 1
  • 1

4 Answers4

6

This is a variable variable. They work by using a variable to contain the name of another variable like so:

$var = 'test';
$test = 'echod variable';
echo $$var;
// output echod variable
Treffynnon
  • 21,365
  • 6
  • 65
  • 98
1

It's a variable variable:

Sometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

dynamic variable name,

for example

for($i = 0; $i<10; $i++)
{
  $var_name = "d".$i;
  echo $$var_name;
}

will echo the variables $d0, $d1, $d2, $d3... $d9

Yaron U.
  • 7,681
  • 3
  • 31
  • 45
0

running this code would set $name

$value="name";
$$value="testing";

in other words, $name is now equal to "testing"

Adam Fowler
  • 1,750
  • 1
  • 17
  • 18