Is it possible to delete one value from a session variable?

When a user adds a item to his cart, it will update the session variable with the unique id for that item.

eg.

item|a:5:{s;i:66578;i:1;i:3456;i:2;i:3284;i:3;i:1232;i:4;i:23423;}
count|i:5;

What I want to achieve is, if the use does not want a specific item
in the cart, they delete that item alone.

Thanks

    Okay, I'm not to sure of the exact methodology that you're using, but it looks like you have some sort of static delimiter. Please refer to the explode and in_array functions to see how to do this. Basically, you'd turn it into an array, then check if the item's ID exists in the session variable.

    However, there's better ways of doing this. Why don't you use a database for this? It would make your life a lot simpler!

      To remove a session variable, you can use:

      unset($_SESSION[index])

      In your case, it looks like you might want to use:

      unset($_SESSION['item'][index]);
      $_SESSION['count'] = $_SESSION['count'] - 1;
      

      I guess. It would have been easier to tell if you had posted the session contents as an array instead of a serialized string.

        Thanks man, I will give it a bash, and see what happens.

          It is to much coding overhead ( explode the array and then go and find it with in_array) to do something simle. I have got a assoc array, and used "tbone-tw" method just to unset it, was simple enough.

          Thanks

          Jakes

            Write a Reply...