Solved

Session Variables

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Node.js 11 82
embadded search engine in website 4 47
Export Data from MySql Using PHP 16 67
Link Stopped Working 7 32
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

751 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