Jump to content

[SOLVED] unset madness


richrock

Recommended Posts

I'm using a $_SESSION array to store some information on images for later comparision, and that's working fine, the remove images from list is fine too, except for one thing:

 

If I have a list of 5 images (the maximum allowed) like this:

Image 1

Image abc

New jpeg

Alt Image

Last Image

 

And try to remove any of teh first four images (Image 1 - Alt Image), the unset function just removes the last image.  I'm sure I've set this up correctly.

 

But is this code correct?

 


if ($_POST['remove'] != NULL) {

if ($_POST['remove'] == 'nothing_a') {
        $key = '0';
    }
    if ($_POST['remove'] == 'nothing_b') {
        $key = '1';
    }
    if ($_POST['remove'] == 'nothing_c') {
        $key = '2';
    }
    if ($_POST['remove'] == 'nothing_d') {
        $key = '3';
    }
    if ($_POST['remove'] == 'nothing_e') {
        $key = '4';
    }

            unset($_SESSION['sess_maker'][$key]);
            unset($_SESSION['sess_location'][$key]);
            unset($_SESSION['sess_year'][$key]);
            unset($_SESSION['sess_image'][$key]);
            unset($_SESSION['sess_type'][$key]);

// Code continues using array_merge and array_pop to reset the array with new values
}

 

Most examples I've seen use unset like this :

 

unset($_SESSION[$key]);

 

Any ideas would be welcome, TIA

Link to comment
https://forums.phpfreaks.com/topic/159279-solved-unset-madness/
Share on other sites

turns out that PHP wasn't reading the [$key] value as it was after the $_SESSION['sess_maker'] string... had to work it out another way.. but thanks anyway.  I had explored what the session was outputting before and after this part of the script ran, but the whole thing was a bit of a mess and I started from scratch...  :-\

Link to comment
https://forums.phpfreaks.com/topic/159279-solved-unset-madness/#findComment-842453
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.