Accessing session arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Accessing session arrays

Post by lostboy »

Hi All,

Question: when accessing a session variable array, how can I write it?

is the correcnt syntax

Code: Select all

for($x=0;$x<$_SESSION&#1111;'numbooths'];$x++;)&#123;
	print "Booth #:".$_SESSION&#1111;'booths']&#1111;$x];
&#125;
or

Code: Select all

for($x=0;$x<$_SESSION&#1111;'numbooths'];$x++;)&#123;
               print "Booth #:".$booths&#1111;$x];
&#125;
TIA
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

if you set the session variable with

$_SESSION['numbooths'] = 3;

you would access it as you have done - obviously declaring session_start() somewhere prior.
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

pootergeist wrote: you would access it as you have done
Yes...but which syntax is correct? the first ex or the second?

TIA
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

If you have register_globals set to off then only the first exemple will work otherwise either are valid.
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

thanks that cleared it up :P
Post Reply