Solved

Session Variables

Posted on 2004-09-02
5
208 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now