Forum Moderators: coopster

Message Too Old, No Replies

Deleting item from shoppingcart

         

arozzi

12:51 am on Jun 6, 2003 (gmt 0)



I am new to PHP and don't really know the functions that well.
I have a shopping cart that is a multidimensional array that looks sth like this.

$product = array("ID"=>$id1, "name"=> $name1, "colour"=>$colour1, "quantity"=>$quantity1, "size"=>$size1, "price"=>$price1);

$cart[$pos] = $product;

I want to be able to delete an item from the cart but can't find any good way to do it.
One way I consider is using the unset function but then one position will be empty unless i restructure the array manually.
THis must be a common task to delete from carts so what is a good way to do it?

jatar_k

1:23 am on Jun 6, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld arozzi,

What about using array_splice [php.net]?
I am not 100% sure of the syntax but look carefully at the comments. It looks like it may work.