i got this PHP question from my friend about variable dollar sign
Possible Duplicate:
what does $$ mean in PHP?
what is the different between $thisvariable and $$thisvariable. as you notice, the first variable has one dollar sign while the second got two dollar signs.
$variable
is a variable and $$variable
is a variable variables,
$my_name = "anthony"; // variable $my_name
echo $my_name; // outputs "anthony"
$a_var = "my_name"; // assigning literal to variable $a_var
echo $$a_var; // outputs "anthony"
It may be a bit confusing, so let's break down that echo call,
$($a_var)
-> $(my_name)
-> $my_name = "anthony"
Please note that the above may not be what happens behind the scenes of the PHP interpreter, but it serves strictly as an illustration.
Hope this helps.
$thisvariable
is a variable named $thisvariable
:
$thisvariable = 'Hello';
print $thisvariable; // prints Hello
$$thisvariable
is a variable variable:
$thisvariable = 'Hello';
$Hello = 'Greetings';
print $$thisvariable; // prints Greetings ($$thisvariable is equivalent to $Hello)
For the most part you should avoid using variable variables. It makes the code harder to understand and debug. When I see it it's a red flag that there's some bad design.
链接地址: http://www.djcxy.com/p/59090.html上一篇: $$在php中是什么意思?