Created
July 12, 2013 17:21
-
-
Save irazasyed/5986152 to your computer and use it in GitHub Desktop.
PHP: Strpos Array, Find in array!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* strpos that takes an array of values to match against a string note the stupid argument order (to match strpos) */ | |
function strpos_arr($haystack, $needle) { | |
if(!is_array($needle)) $needle = array($needle); | |
foreach($needle as $what) { | |
if(($pos = strpos($haystack, $what))!==false) return $pos; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, you need to check for the FIRST occurence form all characters. Your current logic gives you the first occurrence of the top array elements. Here is the corrected logic: