Re: SESSION array problems
| From: | Henrik Hudson | Date: | Wed, 01 Oct 2008 21:05:33 +0000 |
| Subject: | Re: SESSION array problems | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-281348@lists.php.net to get a copy of this message | ||
On Wednesday 01 October 2008, tedd <tedd.sperling@gmail.com> sent a missive
stating:
> At 2:43 PM -0500 10/1/08, Afan Pasalic wrote:
> >just tested. works fine
> >
> >
> >
> >$_SESSION = array(
> > '6156' => array(
> > 'first_name' => 'Diane',
> > 'last_name' => 'Cable'),
> > '7030' => array(
> > 'first_name' => 'Fred',
> > 'last_name' => 'Cago'),
> > '656' => array(
> > 'first_name' => 'Helen',
> > 'last_name' => 'Cahalan')
> > );
> >
> >echo '<pre>';
> >print_r($_SESSION);
> >
> >foreach ($_SESSION as $key => $value)
> >{
> > echo $_SESSION[$key]['last_name'].',
> >'.$_SESSION[$key]['first_name'].'<br>';
> >}
> >
> >-afan
>
> -afan:
>
> That's fine, but that's not the problem.
>
> The problem is:
>
> $_SESSION['user_id'][] = '6156';
> $_SESSION['first_name'][] = 'Diane';
> $_SESSION['last_name'][] = 'Cable';
>
> $_SESSION['user_id'][] = '1234';
> $_SESSION['first_name'][] = 'Big';
> $_SESSION['last_name'][] = 'Ron';
>
> $_SESSION['user_id'][] = '8867';
> $_SESSION['first_name'][] = 'Joe';
> $_SESSION['last_name'][] = 'Dirt';
>
> Now, how do you retrieve it?
I still see an index mixing issue here for you. However, on a side note, why
don't you create user objects and then just stick the object(s) in the
$_SESSION array? Then just while() loop the session and pull the objects out.
Henrik
--
Henrik Hudson
lists@rhavenn.net
------------------------------
"God, root, what is difference?" Pitr; UF (http://www.userfriendly.org/)