Re: [PHP] Array remove function?
- From: paul@xxxxxxxxxxxxxxxxxxx (Paul Novitski)
- Date: Tue, 10 Apr 2007 15:39:53 -0700
At 4/10/2007 03:09 PM, M.Sokolewicz wrote:
Such a function is inherently a Bad Idea (tm). array-values are not unique. Array keys are. So unless you want to emulate the way array_flip works (bad idea (tm)), I'd say: leave it be.
Whoever owns that trademark has totally got to be the wealthiest person in this battered old world~
I guess one could argue that if the array values must be unique then you could use the associative array keys to hold those values; then you can use unset() to remove selected keys which *are* the values. If both keys and values are unique, I'd consider (if only briefly) maintaining two arrays, one a flipped version of the other, so I could look up key/value pairs using either node.
If the values aren't unique and you want to remove all array elements with a given value, you might use array_walk().
Flipping the array back and forth just to unset individual elements seems extremely inefficient. Besides, if the element values aren't unique, won't flipping the values & keys eliminate array elements that share the same value?
Regards,
Paul
__________________________
Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com .
- Follow-Ups:
- Re: [PHP] Array remove function?
- From: Jochem Maas
- Re: [PHP] Array remove function?
- From: "Richard Lynch"
- Re: [PHP] Array remove function?
- References:
- RE: [PHP] Array remove function?
- From: "Daevid Vincent"
- Re: [PHP] Array remove function?
- From: "Tijnema !"
- Re: [PHP] Array remove function?
- From: Lori Lay
- Re: [PHP] Array remove function?
- From: "M.Sokolewicz"
- RE: [PHP] Array remove function?
- Prev by Date: Re: [PHP] Where to insert a phrase in the right place
- Next by Date: Re: [PHP] Bind IP with fsockopen
- Previous by thread: Re: [PHP] Array remove function?
- Next by thread: Re: [PHP] Array remove function?
- Index(es):
Relevant Pages
|