Re: Array remove function?

From: Date: Tue, 10 Apr 2007 22:39:53 +0000
Subject: Re: Array remove function?
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-252493@lists.php.net to get a copy of this message
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

« previous php.general (#252493) next »