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

SAP Logon Failed
I tried to login to SAP through MMC.

When i click start and give password.

it

Allowing ' and "
Hello everyone,

I am creating a form where users submit information to go into a database. I

Shuffle Array
Hi,

I am writing a script for a game that needs players to randomly be assigned a target (ano

Array to string conversion
Can anyone help me with this?

Notice: Array to string conversion in /home/..../index.php on l

Need help adding a timestamp to my filename/variable
Hello,

I'm kind of stupid when it comes to php and I need a tiny bit of help. I've got a f

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

Find current logon time
Hi,
in my sql script i want to query and find out the logon time of the current session.
<

please help me... my password gets encrypted but not able to get in database
hai guys,
please help me... in the following function my password gets encrypted but no

upload image name with extension using php
hi frds..

<input id="file1" type="file" name="file[]" &a

LinkedList help
Ok so I just learned quickly about lists, so I have a not too hard project I think, but am having a

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