tags:

views:

66

answers:

3

I have a largish array of string that I want to use as a lookup.

I a using in_array(), but I suspect its doing a simple loop through - does anyone know whether the in_array() algo uses a bsearch algo?

+2  A: 

in_array() uses a linear (O(n)) search rather than a binary (O(log n)) search.

If you want O(log n) or better I would suggest you either put the values you want to search as the keys in an array or you create an index structure that effectively does the same thing.

cletus
+6  A: 

in_array() is O(n). Also see http://stackoverflow.com/questions/2473989/list-of-big-o-for-php-functions

ThiefMaster
+3  A: 

Since it doesn't require the array to be sorted, I don't see how it could do a binary search.

nc3b