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?

No comments posted yet

Your Answer:

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

PHP page loading in Firefox but not in IE
hello,

i am currently doing a project in PHP and i have a problem. If I view the project in M

Can we convert non uni code system into unicode
Hi All,

Presently i am using non-unicode system and the sap version is 4.7.
Can i c

Reduce redundancies in switch functions?
Hello all! I somewhat new to PHP, and was wondering if anyone could give some suggestions on a swit

Packet Design
Hi All,
Im new about network programming and I want to design a protocol but I have some question

Random date selection
i want to select random date with time(hour+minutes+sec) where date is specified(10/22/2009) and tim

problem with script manager
Hi iam using Net.2005.I have created ajax enabledwebsite.i have master page in which i have script m

form help
this doesn't work. i want the form action to go the location.href of the submit button chosen.. how

Big Problem!! Please help
Hi Guys,

Im making a website for a friend have encountered a really annoying problem. When ev

what are '%S%', '%E%'
for example when i see Code: [Select]printf("Hello %srn", $name);
what does %s means

double and single quotes in text fields acting up... help please
Single quotes, when entered into a text field, create an sql error upon Submit. It seems to create t

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