What is the difference between $a and $$a in php? $a = 10 and $$a = 10 are working as same. But $$$a is not working.
variable declaration
Collapse
X
-
Originally posted by AMT IndiaWhat is the difference between $a and $$a in php? $a = 10 and $$a = 10 are working as same. But $$$a is not working.
Try the manual: http://www.php.net/manual/en/language.variab les.php
Or http://php.net/manual/en/language.variab les.variable.ph p
I think it would work if you used ${${$a}} but not sure. -
Heya, AMT India.
$$a is a 'variable variable'. PHP evaluates the rightmost part of the expression ($a) and then uses that value with the left part.Originally posted by AMT IndiaWhat is the difference between $a and $$a in php?
So for example:
[code=php]
$name = 'red';
$red = 50;
$green = 75;
$blue = 100;
echo $$name; // evaluates to ${'red'} -> $red -> 50
[/code]
If you get to the point where you're using variable variable variables, you might want to rethink your application design.Originally posted by AMT India$a = 10 and $$a = 10 are working as same. But $$$a is not working.Comment
Comment