Hi,

I've got a shopping cart script and want to be able to remove individual items from the arrays that store the purchase data.

I've created a remove link:

<a href='$PHP_SELF?remove=1&i=$i'>Remove</a>

// remove item
if($remove)
{
unset($name[$i]);
unset($size[$i]);
unset($cost[$i]);
}

$i being the array key for the item. The unset doesn't work and i've tried array splice but that just deletes everything..

Please help.

    Perhaps this is a silly question, but are you using a full path to unset your item? I'm assuming you're wanting to remove these items from a database, and not just the array itself.

    Also, maybe instead of unset (totally removing it), you could set it active or inactive.

    At any rate, my use of unset has been to remove files from servers, not from arrays.

      I wanted to put some code in here to try and explain what i'm doing. unset just happened to be the last thing i tried.

      all I want to do is remove an item from the array using its given key.

        try this....

        $thearr[0] = "top";
        $thearr[1] = "ramen";
        $thearr[2] = "is";
        $thearr[3] = "good";
        
        array_splice($thearr, 2, 1);
        
        

        this would remove "is" from the array

          Write a Reply...