View Full Version : Session Variable variable

01-30-2012, 05:34 PM


$dox="_SESSION['" . $pox . "']";

echo $$dox;

N.B. The output should be 'john'. But I did not get the expected result. Can anyone please help me? I am grateful to this site because I got the first free help on php from this site.

01-30-2012, 06:08 PM
You don't need a variable variable for this; you can simply use the string as a key:

echo $_SESSION[$pox];

01-30-2012, 06:15 PM
variable variables are always a terrible idea.
This is an array, not a variable. You cannot pull a variable variable directly from an array for that you need eval. You can pull $_SESSION[$pox] though, so there is absolutely no reason to use a variable variable (as there never is anyway).