Jump to content


Photo

Session Variables - 2 Questions


  • Please log in to reply
2 replies to this topic

#1 scott212

scott212
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 18 July 2006 - 02:06 AM

I've seen people use session variables with a second indexes like this: $_SESSION['id_01']['id_02']
I can't seem to find any documentation on this method, anyone have any links? If it works like it seems, what would the syntax be to iterate through the second indexes within the confines of a first id? Such as if I had:

$_SESSION['basket']['01'], $_SESSION['basket']['02'], $_SESSION['basket']['03']

How could I iterate through the different items in 'basket' using a foreach or for loop?


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 18 July 2006 - 02:16 AM

The $_SESSION array is just like any other array. What your looking at is just a multidimensional array. To loop through it (as per your example)...

foreach($_SESSION['basket'] as $var) {
  echo $var;
}


#3 scott212

scott212
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 18 July 2006 - 02:23 AM

I figured it out right as you posted this, what an excellent thing! Guess I've just avoided the complexity of multidimensionals, now I wish I wouldn't have, thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users