Hi guys,

I have a simple php shopping basket which stores the products in an array.

To add a new value into the array, I have the following:

$cart .= ','.$_GET['id'];

I was just wondering if there is an equivalent line of code to remove a single array value with a particular id??

I've been wrestling with the unset() function without much success.

Thanks

$cart .= ','.$_GET['id'];

This does not add a new value to a array..

It appends a comma and the value of a url parameter to a string.
Since your using a string unset() is not going to work.

gr,
Yrm

Aha. my bad. This makes sense, as the explode() function is used on the $cart string to get the array back.

So I must explode and loop through the array values to remove one of them.

you can use unset() after you exploded that string..

edit:
it is indeed easier to loop through the array because you probably dont know the position of the value you want to remove

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.