...

View Full Version : Session Variable variable



blankskull
01-30-2012, 04:34 PM
session_start();
$_SESSION['jobs_username']="john";

$pox='jobs_username';

$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.

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

echo $_SESSION[$pox];

Fou-Lu
01-30-2012, 05: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).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum