I have an array of items on which I would like to apply search function. I am considering sorting the array and simply applying binary search for now as it need not be too complex, however if I run into problems I'll try other methods.
My question is; what is the search algorithm used in the array_search()? If it is indeed binary search I can use that.
It has to be sequential search, because the array might not be sorted.
If you need to search an array often, use array_flip to convert it to an associative array where the values become the keys. Looking up keys in an array is a hash lookup.
PHP performs a linear search - here's the source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With