Solved

Session Variables

Posted on 2004-09-02
5
232 Views
Last Modified: 2006-11-17
I know how to use session variables but I would like to know if it is possible to use an array for a session variable. If so is there anything special that one needs to do.

Thanks for the help

Richard G Hurley
0
Comment
Question by:RICHARDH
  • 3
5 Comments
 
LVL 27

Accepted Solution

by:
Diablo84 earned 50 total points
ID: 11966481
various method, examples:

$_SESSION['anarray'] = array("one",two","three","etc");

or

$_SESSION['anarray'][] = "one";
$_SESSION['anarray'][] = "two";
$_SESSION['anarray'][] = "three";
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11966514
The above will use numeric indexes for each array items (as normal) beginning with 0 and incrementing for each item. If you want associative indexes you can do:

$_SESSION['anarray'] = array("key1" => "one", "key2" => "two", "key3" => "three", "key4" => "etc");

or

$_SESSION['anarray']['key1'] = "one";
$_SESSION['anarray']['key2'] = "two";
$_SESSION['anarray']['key3'] = "three";

so

echo $_SESSION['anarray']['key2'];

will output the string "two";
0
 

Author Comment

by:RICHARDH
ID: 11966696
Thanks for the help.

I assume that one the session array has been set up, I can keep referring to it and adding new values.

0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11966719
Thats correct, just think of it as a global array (which is effectively what it is).
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question