save array as a session?

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
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

save array as a session?

Post by lafflin »

hello, I am trying to store several input values into an array as a session. here is the code i have used:

Code: Select all

$student_info= array($fn, $ln, $dob, $sex, $school, $medical, $notes) ;
			   $_SESSION['stud_info']=$student_info   ;
it works and the var_dump
looks like this:
array(7) { [0]=> string(6) "pierre" [1]=> string(7) "hobstra" [2]=> string(8) "20030809" [3]=> string(1) "m" [4]=> string(4) "null" [5]=> string(32) "these are all my medical issues." [6]=> string(70) "blah blah blah blah blah blah blah....that\'s all she ever says to me." }
which seems to be good to me, I don't know why there is curly braces, but I have never tried this before either. I'm just learning.

then I try to call the one of the values like this:

Code: Select all

var_dump ($_SESSION['stud_info[1]']);

it doesn't work, I get NULL.

can anyone tell me what I'm doing wrong? what would be the best way to do this?

Thanks.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

var_dump ($_SESSION['stud_info'][1]);
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

Post by lafflin »

vielen Dank
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

let me know if when you do that it outputs "The Ninja Space Goat" (super stud)

(sorry I couldn't help myself... I'm a stud :lol: )
Post Reply