I'm working on a shopping cart, and i have one variable to set the items of the shopping cart, separated by commas then exploded into an array. I'm working on the remove an item part of it and i cant figure out fully functional way to do this. I'm using str_replace to remove it from that string of text, but where the problems come in depend on where its at in the variable.
What i have come up with so far, say the variable is "item1,item2,item3,item4" then if item 2 is removed it will become "item1,,item3,item4" and then replace ",," with ","
So what i need to figure out is if the first item or last item is removed, how do i get rid of a comma at the beginning or end, or if someone has a better method of doing this.
Thanks in advance.