Search array faster than in_array()

<php /** * Now, if you have a partial value you can also check using str_pos in your if condition. * * This is just stupid faster. You will be amazed if you benchmark it. * $haystack - is the original array of course * $needle - is your search * $new_haystack - is a temporary array to assign the values to the key in the array */ $new_haystack = array_flip($haystack); if(isset($new_haystack[$needle])) { echo $needle, ' found in $haystack', "\r\n"; } // cleanup for memory unset($new_haystack);

1 Response

Try the hacky way :) → https://codepad.co/snippet/UyE42ShZ

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.