[DGD] Remove Multiple Instances from Array

Michael McKiel crashnbrn71 at yahoo.ca
Tue Apr 6 09:37:56 CEST 2004


Just thought I'd throw this out there, if someone might have use of it, was
something I came up with to preserve order of elements.

keys = explode(str, " ");

/* Remove multiple instances of the same word, preserving order. 
** Note: >= 1; we don't check the first element since previous
** matching elements in the arrary were already removed.
*/
for (i=sz=sizeof(keys); --i >= 1; )
{
    if (keys[i] == "" || sizeof(({ keys[i] }) | keys) != sz)
        keys[i] = nil;
}
keys -= ({ nil });


Oh yeah I stole Par's comment style ;)


______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca
_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list