By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,107 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,107 IT Pros & Developers. It's quick & easy.

Access $_SESSION values via an index instead of a name

P: n/a
Is there a way to access the values from a session by using an index/count
instead of the name?

Something like:

$_SESSION[1]

Also, can you query the name and value for this?

What I am looking to do is have a lot of different variables stored in my
session but the names may change or be different.
--
Chuck C
ElSeeker.at.hotmail.com
Software Developer
Mar 2 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Chuck C wrote:
Is there a way to access the values from a session by using an index/count
instead of the name?

Something like:

$_SESSION[1]

Also, can you query the name and value for this?

What I am looking to do is have a lot of different variables stored in my
session but the names may change or be different.


I do not see why note -- it is simply an array.

If you are going to have a dynamic amount of keys in your sessions, then
you should put an array inside your session array. Example:
$_SESSION['myarrary'] = array(1,2,3,4);

Carl

--
Carl Vondrick
www.carlsoft.net
usenet [at] carlsoft [dot] net
Mar 2 '06 #2

P: n/a
Chuck C wrote:
Is there a way to access the values from a session by using an index/count
instead of the name?

Something like:

$_SESSION[1]

Also, can you query the name and value for this?

What I am looking to do is have a lot of different variables stored in my
session but the names may change or be different.

I just had to do something similar like this:

$good = array();
foreach( $_SESSION as $key => $value ) {
switch( $value ) {
case 'good1':
case 'good2':
case 'good3':
$good[] = $value;
break;
default:
unset($_SESSION[$key]);
}
}

Not the prettiest, but it got the job done.

-david-

Mar 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.