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
  • 20,415
  • 5
  • 59
  • 95
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
  • 960,118
  • 257
  • 3,196
  • 2,876
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.
  • 6,921
  • 2
  • 28
  • 45
0

running this code would set $name

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

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

Adam F
  • 1,724
  • 1
  • 16
  • 18