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

Why doesn't this work? (SSH2)
This is my script:

Code: <?php
$connection = ssh2_connect('213.251.167.109', 22);

Wierd echo error?
Hi, i got the most wierd php error ever and i don't know why..
Code: echo "<t

Product categories for registration
Dear all,

We are going live with the Supplier registered next week. At standard, the 'sel

pop3 and fsockopen
So I am able to connect to the pop3 server, log in, and check how many messages there are. I am hav

ALV sum various columns problem
Hi all,
I'm doing a report on ABAP for a timesheet of the current month. The output i want is s

Rss feed question
Hi

My blog and my website are different. Am i able to take my rss feed
from my blog and p

Can I call a class inside a function?
I have a class written in another file that handles my image resizing.

Can I do this (php say

foreach help.
Hello all,

First time I'm attempting to use a foreach statement and was just wondering if my

Multi Level Array Problem
hi all,

For example I have array like below:

$temp = array(array('north america', 'us'

explode() function problem maybe
Hi I'm having trouble searching my database. When I type two words in the search field it only searc

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