How to store checkbox array in a session, and then be able to add to it?


Posted on 16th Feb 2014 07:03 pm by admin

I'm trying to store an array of checkbox values into a session array, sort of like a shopping cart, but I can't figure out how to not overwrite the sessions array each time new checkbox values are added to the stored session...

Here is an array that is created upon submitting with two checkboxes checked:

Did you know?Explore Trending and Topic pages for more stories like this.
Code: Array
(
[0] => 606613
[1] => 606614
)
And then my sessions array is now like so:

Code: Array
(
[checked] => Array
(
[0] => 606613
[1] => 606614
)

)
The code for that so far is this:

<?php
if (!isset($_SESSION['checked'])) {
$_SESSION['checked'] = array();
}
$_SESSION['checked'] = $_GET['new_checked'];
?>

I know I probably need to add a loop that checks the arrays, but I just can't think how I should go about adding newly checked checkbox values, that are not duplicates, to the *end* of the session array "checked"??

Would anybody care to share some ideas?
No comments posted yet

Your Answer:

Login to answer
340 Like 33 Dislike
Previous forums Next forums
Other forums

Looping Problem
I've got a client that has a database with about 200 events at any given time. I'm trying to loop t

Please help - should be a simple fix.. driving me nuts
Everything seemed to be working fine. I have a table, it alphabetically lists a bunch of cities and

What are causes of a connection-timeout with fopen()?
Hello! Here is the situation: The server I host my website on just upgraded it's PHP build from 4.4.

how to transport the Query and insfoset
Hi

I have created the query using SQ01........
How to created T-code for query..

chat
hello i'm amir i need a chat source code in asp.net 2.0 without Ajax. anybody can help me?

Need help in log in and log out?
hi there all of u. i have recently created a site for someone. i have placed log in and log out and

GIS appliction help
I found some tutorials in the internet to develop a map application I don't want to use google maps

Array question
Does anyone know how to create a program that takes the $ amount for 8 different departments and gi

Quick variable question
hey guys/gals,
im trying to write a php script and it works fine as i have it, but i need to set

Login logout link help
Hi all,

Im new to php and Im having trouble creating a login/logout link for my page that dis

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash