...

View Full Version : what does $$ in php means?



akosiana
11-24-2011, 04:40 AM
I know $ is for variables but what does $$ means?

mlseim
11-24-2011, 05:18 AM
"variable variables"

It's hard to describe because it sort of bends your mind ...
at times, I get so lost in it, like a paradox.

Take a look here and let me know if it messes with your mind ...
http://php.net/manual/en/language.variables.variable.php


.

XterM
11-24-2011, 07:48 AM
$a = "value of var a";

$b = "a";

echo $$b;


simple example. hehe.

Fou-Lu
11-24-2011, 05:48 PM
$a = "value of var a";

$b = "a";

echo $$b;


simple example. hehe.

This is about the easiest way to think of it. Variable variables are simply dereferencing two levels of variables. So dereferencing $b becomes 'a', and then it seeks to dereference 'a' with a returned result of 'value of var a'.
The only thing I have to add is that there is yet to be a situation in which I've found variable variables useful. Standard copy assignment or referenced variables do exactly the same, except referenced assignments cannot swap what they point at ($b can be changed to point at $c, and $$b would then dereference $c instead of $a, but there is little use to variable variables at all).
Variable variables would actually be quite popular if PHP didn't use copy-on-write optimization. Since it does, variable variables are pretty much obsolete.

mlseim
11-24-2011, 09:17 PM
oops ... double posted.

mlseim
11-24-2011, 09:21 PM
This is about the easiest way to think of it. Variable variables are simply dereferencing two levels of variables. So dereferencing $b becomes 'a', and then it seeks to dereference 'a' with a returned result of 'value of var a'.

:o like I can understand that.

I've only used them one time, with Perl.
I don't remember why I needed to use them.

XterM
11-25-2011, 01:59 AM
This is about the easiest way to think of it. Variable variables are simply dereferencing two levels of variables. So dereferencing $b becomes 'a', and then it seeks to dereference 'a' with a returned result of 'value of var a'.
The only thing I have to add is that there is yet to be a situation in which I've found variable variables useful. Standard copy assignment or referenced variables do exactly the same, except referenced assignments cannot swap what they point at ($b can be changed to point at $c, and $$b would then dereference $c instead of $a, but there is little use to variable variables at all).
Variable variables would actually be quite popular if PHP didn't use copy-on-write optimization. Since it does, variable variables are pretty much obsolete.

wow. that is very understandable. thanks bro :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum