[PHP] Dynamically Referencing Variables?

arxanas

New member
I'm trying to dynamically reference a variable using variable variables. For example, this:
$var1 = "hi";
$var2 = "something else";
$var3 = "asdfhjkl";
$varname = "var1";
echo $$varname;
I'm trying to make it say "hi", here. However, all the examples I've looked at online only use variable variables to set another variable, instead of get the value from it. Is this legal syntax, or should I use something else?
 
Back
Top