2
$arr1 = array ("llo" "world", "ef", "gh");
什麼是最好的方法來檢查$str1
以$arr1
的字符串結尾? 雖然知道$ arr1元素的數目作爲答案(如果爲真)會很好,但答案true/false很好。php:檢查字符串是否以數組元素結尾的最佳方法?
例子:
$pos= check_end("world hello");//$pos=0; because ends with llo
$pos= check_end("hello world");//$pos=1; because ends with world.
有沒有更好的/快/特殊不僅僅是比較在語句的$arr1
所有元素與$str1
末呢?
可能重複startsWith()和endsWi th()函數](http://stackoverflow.com/questions/834303/php-startswith-and-endswith-functions) – 2012-04-24 11:14:03
'$ arr1'是'$ arr1'的另一個值的結束子字符串嗎?因爲如果s/t像'$ arr1 = array('llo','lo','hi')'是可能的,你需要進一步澄清在多個匹配情況下應該返回哪個元素的數字。 – 2012-04-24 11:34:54
謝謝。 'llo'或'lo'作爲答案都很好。 ($ arr1元素中沒有一個實際上是另一個的子串,它們是預定義的)。但是,感謝您的通知。 – Haradzieniec 2012-04-24 12:10:50