473,508 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Arrays with $_SESSION

I'm really confused on how to store arrays in a $_SESSION.

Right now to access an array I basically do this:

$lc = $_SESSION["cart"];

$lc[$item] = 1;
(plus some other manipulative code)

$_SESSION["cart"] = $lc;

Is there a better way to do this? I can't seem to figure out a proper
way to include the array index inside the same line as $_SESSION (such
as $_SESSION["cart($item)"].

--
- Michael J. Astrauskas

Jul 17 '05 #1
1 4324
Michael J. Astrauskas wrote:
I'm really confused on how to store arrays in a $_SESSION.

Right now to access an array I basically do this:

$lc = $_SESSION["cart"];

$lc[$item] = 1;
(plus some other manipulative code)

$_SESSION["cart"] = $lc;

Is there a better way to do this? I can't seem to figure out a proper
way to include the array index inside the same line as $_SESSION (such
as $_SESSION["cart($item)"].


$_SESSION["cart"][$item] = 1;
(and other manipulative code)
--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4418
by: Jerry | last post by:
Hi there: A quick question, if anybody can give me a helping hand? Can an array be stored in a session variable???? Or will the variable of the type $_SESSION hold scalar values only? My...
3
1840
by: Terry Richards | last post by:
this is prolly too simple but i got a brain block i have two arrays, one is days and the other is timeofday,<each letter represents a time on the hour> how do is sort by days and put each day's...
3
1545
by: LMachado1 | last post by:
I just started with php and I'm trying to make a simple interface as follows: - user is asked to input an integers, for example: how many students do you want to enter? - user is then shown a...
5
1846
by: h | last post by:
I am at my wits end; I can not see A SINGLE THING I'm doing wrong. I've read every fricking session related doc. I've searched every fricking group. NO ONE seems to have had the problem I'm having...
8
1598
by: mantrid | last post by:
Hello Im having problems working out why the following code does not work. I dont think its the sql as the error occurs on the first update which ever one is put there ($q1 or $q2). Ive swapped...
12
2873
by: mantrid | last post by:
Im trying to move a file but am having luck my code is below. The temp and target paths are valid as they echo correctly. but I cant get the copy() function to work, or the rename() function ...
1
1974
by: billkirim | last post by:
hi guys.. can anyone help me with that staff? here is my code.. $cart = $_SESSION; $action = $_GET; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET;
3
1116
by: lister | last post by:
I have the following code: $Foo = new CFoo(); $Foo->Bar = 5; $_SESSION = $Foo; $_SESSION = $Foo->Bar; $Foo->Bar = 10;
4
7730
Tarantulus
by: Tarantulus | last post by:
Hi Ladies/Gents/Other I'm having issues with nested arrays, I need to set an array key by variable but whenever I do I get an error "invalid offset in XXXXX" here is the code causing the...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.