note 92838 deleted from function.in-array by danbrown
| From: | danbrown@php.net | Date: | Fri, 01 Oct 2010 19:56:02 +0000 |
| Subject: | note 92838 deleted from function.in-array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172879@lists.php.net to get a copy of this message | ||
Note Submitter: steakpinball+php at gmail dot com
----
The function which Robin is proposing is known as an Iterative (as opposed to Recursive) Binary
Search. It is indeed faster, but can only be used in situations when the haystack is in ascending
order. If the haystack is not sorted it may return incorrect results. For this reason it cannot
always be used as a direct replacement for in_array. For general purpose arrays, in_array is as good
as it gets.