Using Variable Variables in PHP - Variable Variables? (
Page 2 of 7 )
A variable variable is, in short, a method of using the value of one
variable to call the name of another. For instance, if I had a variable $x with
the value of "Eric", I could set a variable $Eric to "Seufert" by simply writing
$$x = "Seufert". This process calls the value of $x and then creates a variable
out of it. Therefore,
echo "$x ${$x}";
would produce the same output as,
echo "$x $Eric";
which is:
Eric Seufert
Notice the curly braces around the variable variable in
the first echo statement. This is the standard syntax for outputting variable
variables. Omitting the curly braces would have resulted with the following
output:
Eric $Eric