You think,know the answer,eh? in_array() v array_search() v foreach v array_flip+isset
Compare usual methods to search in arrays
https://github.com/hosseinmousavi/php-fastest-array-lookup
/////////////////////////
For Test I Create a Haystack Array with 100,000 Items and 200 Character Length Each and Choosing a Needle at the End of It. The Is the Result by Windows 10+4G Ram:
///////////////////////// found by inarray takes 0.0015938282012939 seconds
///////////////////////// found by arraysearch takes 0.001533031463623 seconds
///////////////////////// found by foreach+"==" operator takes 0.028446912765503 seconds
///////////////////////// found by array_flip+isset takes 0.10690093040466 seconds
Written by pepsiphone
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Related Tags
#php
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#