The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Deleting something from an Array

Okay, well in my coding, I never use arrays, or not very often. When I do, I've never had to delete them.

For a recent wishlist project, I decided to save the trouble of having tons of MySQL rows, and just create one in the user table 'wishlist' and have the array (imploded, of course) put there, and exploded, and pulled out on the page.

The problem I've run across is removing things from your wishlist. I've never had to delete things from an array. So, pretty much I need help taking one value out of an array. For example, they may have itemids "1,2,3,4,5,6,7,8" in their wishlist, and I want to remove, say.. 4 from it.

How would I go about doing that?

Edit as far as Unset goes, I'm pretty sure to use it, you have to know where the value of the array is, to use it. I don't know where in the array (ie: $array[1]) the itemid is, so I don't think I can use it. Unless I could reorginize it, and then know its on $array[0] or something.

You will be removing the fifth element in the array, I believe Eradication wanted to remove the item id 4 from the array, not the element which corresponded to [4].

Also by using unset() you are removing the element[4], but if there are elements [5], [6]... they will remain at [5], [6]... they will not collapse. This can cause a problem when using count(), because it will return the number of elements in the array. So if there are 7 elements, and you remove elements [2] and [3] then you call count() to use in a 'for loop', count() will return the integer 5 and you will never get to elements [6] and [7] in the loop.