A have variable with the name a and a variable named b.
Try to print the value of the variable a using the variable b.
And what is the variable variable concept?
Suppose that:
$b = "a";
$a = 1234;
echo $$b;
Result is: 1234
it is the concept of variable of variable. means you can define variables dynamically.
I don't know if you literally meant variable variable
http://php.net/manual/en/language.variables.variable.php
<?php
$a = 'hello';
?>
A variable variable takes the value of a variable and treats that as the name of a variable. In the above example, hello, can be used as the name of a variable by using two dollar signs. i.e.
<?php
$$a = 'world';
?>
At this point two variables have been defined and stored in the PHP symbol tree: $a with contents "hello" and $hello with contents "world". Therefore, this statement:
<?php
echo "$a ${$a}";
?>
produces the exact same output as:
<?php
echo "$a $hello";
?>
i.e. they both produce: hello world.
First time I saw $$var
I thought it was a typo, 4real.
In the above example from http://php.net/manual
they are taking the value of $a
and creating a variable from it. it's value $a = 'hello'
becomes a variable $hello
by using $$a
then they set the new variable's value to $hello = 'world'
here $$a = 'world';
basically.
Personally I never use them, just because it makes reading the code more challenging then it should be. ie. extract()
is similar.
http://php.net/manual/en/function.extract.php
For me, they are just curious features of the language that don't serve any real purpose, but I look at global
the same way too. These things break my IDE's autocomplete so, while interesting, I find them of little practical use. In production code, readability is #1, followed by performance.