Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-30-2012, 04:34 PM   PM User | #1
blankskull
New Coder

 
Join Date: Jun 2010
Posts: 22
Thanks: 9
Thanked 0 Times in 0 Posts
blankskull is an unknown quantity at this point
Session Variable variable

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.
blankskull is offline   Reply With Quote
Old 01-30-2012, 05:08 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
You don't need a variable variable for this; you can simply use the string as a key:
PHP Code:
echo $_SESSION[$pox]; 
Inigoesdr is offline   Reply With Quote
Old 01-30-2012, 05:15 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,639
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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).
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:15 PM.


Advertisement
Log in to turn off these ads.