php - Find position first occurence of an array of strings in a string -


php has function strpos() finding position of first instance of given value in string. there way needle array of strings? give first occurence:

$str = '1st , 3rd';  str_array_pos($str, array('st', 'nd', 'rd', 'th')) //would return 1 because of 'st' 

you write 1 yourself:

function str_array_pos($string, $array) {   ($i = 0, $n = count($array); $i < $n; $i++)     if (($pos = strpos($string, $array[$i])) !== false)       return $pos;   return false; } 

by way, return value in example should 0 , not 1 since array indices start @ 0.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -