Jump to content

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


Scooby08

Recommended Posts

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:

 

Array
(
    [0] => 606613
    [1] => 606614
)

 

And then my sessions array is now like so:

 

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?

 

THANKS!

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.