Favor Hash Lookups Over Array Searches

Author: 
Published: March 17, 2014
Link: http://mtdowling.com/blog/2014/03/17/hash-lookups-over-array-search/
Excerpt: “A common programming requirement is to match a string against a set of known strings. For example, let’s say you were iterating over the words in a forum post and testing to see if a word is in a list of prohibited words. A common approach to this problem is to create an array of the known prohibited words and then use PHP’s in_array() function to test if the string is found in the list. However, there’s a simple optimization you can make to significantly improve the performance of the algorithm.”

Tagged with: , ,
Posted in PHP

Categories