Re: in_array() 4.0.0 -> 4.0.2

From: Date: Mon, 11 Sep 2000 19:21:18 +0000
Subject: Re: in_array() 4.0.0 -> 4.0.2
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-16217@lists.php.net to get a copy of this message
Andrei Zmievski wrote: > > > The purpose of in_array() is to say if an item is in the array, > > with a rather nice side effect of re-positioning the array pointer > > to that element. > > > > How are we to find the position of the element? > > > > I don't want to have to do an expensive for loop every time I > > want to get an index. > > > > Short of coding up a my_in_array() what are the alternatives? > > Hmm, I didn't realize people relied on that behavior. It's possible to > change it back to the old one, but still implement a check that if the > element is not found the pointer is reset to the beginning of the array, > but I guess I'd like to hear more opinions about this before doing any > changes. OK, then, as long as you are fising for opinions. I didn't know the feature existed and so implemented my own "my_in_array". Wish I had known it was built-in: faster and easier. Makes a lot of sense b/c a good percentage of the time that you search for a value you want to know what the key is; on the other hand I have not yet been in a situation where I was worried about moving the pointer by in_array. Of course, using the configurable approach, there could be an optional third argument for "don't move the pointer". Ciao, Andreas Pour http://www.kde.com/ : Everything KDE http://apps.kde.com/: The Latest in KDE Applications

« previous php.general (#16217) next »