[PATCH] New parameter for in_array() & array_search()

php.internals

Hannes Magnusson

19 years ago
Hi all Attached* is a patch introducing a new parameter to in_array() and array_search() which will set the internal pointer to the first location of $needle in the $haystack (granted that $needle exists within the $haystack). This will make it possible to search for a value in an array and then run prev()/next() on the array to get the next/previous sibling. I'd like to commit this after 5.2.4 has been released if there are no objections? -Hannes * In case it doesn't come through: http://home.nith.no/~maghan/keeppos/

Hannes Magnusson

19 years ago
On 8/15/07, Hannes Magnusson <hannes.magnusson@gmail.com> wrote:
> Hi all > > Attached* is a patch introducing a new parameter to in_array() and > array_search() which will set the internal pointer to the first > location of $needle in the $haystack (granted that $needle exists > within the $haystack).
Or should we maybe create two new functions? bool array_seek_value(&$array, mixed $value [, bool $strict=false]); bool array_seek_key(&$array, integer/string $key); -Hannes

David Zülke

19 years ago
Smells like feature creep. Plus, it's difficult to document. I think it would be the first function that mutates an argument depending on another argument - it would also mean that the input array is passed as a reference in case that new flag is set. Either way, not a good idea IMO. Especially in case of in_array(). David Am 15.08.2007 um 16:59 schrieb Hannes Magnusson: