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:

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?

340 Like 33 Dislike
Previous php-forum Next php-forum
Other php-forum

Mail form doesn't send Russian/Cyrillic characters correctly?
When someone enters foreign characters (like Cyrillic text, and Japanese/Chinese probably gives the

How do i do multi uploads?.
Hey i would like to do this : http://hosting.mrkrabz.net/

I've got the base down you can uplo

Optimize Code
Just started getting into the use of cookies. The following code will redirect users to a set URL s

Wordpress IE issue
So I am trying to add the background shadow to my wordpress page. It works fine in Firefox but does

Not "Just Another" MMORPG - text based.
Hello,

I've been learning MySQL and PHP for the last 2-3 years.
Though, I've had long paus

php libs/ browsercap.in
ok i have a host that refuses to stay current. they control my php settings and libs. is there a way

Hits this week counter
I have a counter on my site that tracks hits, IP's, etc. into a mySQL database. It also includes the

Just a white page
Okay so, my website, when I click SignUp on it it takes me to /join.php but its a complete white pag

Need help with some php code :)
Hey! I'm quite new to this whole thing, so please don't fire me with shait on this one =D

I'm

help with contest script
I would like to code a contest script to my site but i don't know how. Could someone just give me pu

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