Re: [PHP] Array remove function?



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 .



Relevant Pages

  • Re: comparing some but not all fields in lists
    ... and what's in common." ... I should compare only 3 of the 82 fields in each list. ... comparing all 82 fields as a single array element. ... cannot handle multiple keys as you want it to. ...
    (perl.beginners)
  • Re: Build an array from a text file
    ... Now that I have created my array, ... The dictionary object has a 'keys' method that returns a 0 based array ... Dim vArray As Variant ... dictionaries, so any help would be great! ...
    (microsoft.public.word.vba.general)
  • Re: Hash table with coarse integer keys
    ... The edges' ids are ordered from 0 to the ... One optimization I came up with was just using a dense array of the ... dictionary with 10 millions of keys randomly chosen between 0 and 20 ... What is the hashing algorithm used by C# Dictionary? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: "map" a deeply nested structure: Object#deep_map
    ... if the key is an Array or Hash? ... I was not interested in mapping keys, but this would be a reasonable ...   when String ...
    (comp.lang.ruby)
  • Hash table with coarse integer keys
    ... The edges' ids are ordered from 0 to the ... One optimization I came up with was just using a dense array of the ... dictionary with 10 millions of keys randomly chosen between 0 and 20 ... What is the hashing algorithm used by C# Dictionary? ...
    (microsoft.public.dotnet.languages.csharp)