0

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

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by MrYrm
0
$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

0

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.

0

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

Edited by MrYrm: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.