tags:

views:

105

answers:

3

what does two back to back $ behind a variable means. Like this $$id

where can I find more information on that Thanks

+1  A: 

in the PHP manual of course

http://www.php.net/manual/en/language.variables.variable.php

note that it's obsolete and senseless syntax and you should always use arrays instead.

Col. Shrapnel
+4  A: 

These are called variable variables.

$foo = 'bar';
$id = 'foo';

echo $id;  // prints foo
echo $$id; // prints bar
codaddict
+4  A: 

In PHP, $$ means you are about to inflict years of pain and suffering on at least one maintenance programmer. Note that you might wind up being that maintenance programmer.

It is a variable variable. Imagine this:

$quux = 'bar';
$foo[$quux] = "baz";
echo $foo['bar']; //prints baz

if there was no such thing as arrays, you might try something like this:

$quux = 'bar';
$$quux = "baz";
echo $bar; //prints baz

luckily we do have arrays so please don't use variable variables unless you are doing something convoluted and magical* and have no other choice.

*: Please don't do convoluted magical things, either.

Carson Myers
You can make anything look convoluted with undescriptive variable names like that. Variable variables are just as maintainable as regular ones when named properly.
Lotus Notes
the foo, bar, baz, etc variables are very common when demonstrating a language feature. Obviously proper use of naming is a must in any language, but I'm talking about the maintainability of variable variables, not of dummy names -- I think they take much effort to use in a way that is not evil, so I'm okay with presenting them in a way that would make a novice programmer approach them with caution.
Carson Myers