Solved

Session Variables

Posted on 2004-09-02
5
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: 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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

626 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