我想尋找一個字符串,並得到相關的值,但在測試中的功能,在各次搜索詞(Title
或者Would
或者Post
或者Ask
)顯示(給)只有一個輸出Title,11,11
!!!!如何解決它?strpos不匹配
// test array
$arr = array('Title,11,11','Would,22,22','Post,55,55','Ask,66,66');
// define search function that you pass an array and a search string to
function search($needle,$haystack){
//loop over each passed in array element
foreach($haystack as $v){
// if there is a match at the first position
if(strpos($needle,$v) == 0)
// return the current array element
return $v;
}
// otherwise retur false if not found
return false;
}
// test the function
echo search("Would",$arr);
一個
===
對比您有鷹的眼睛;-)你說得對。 +1 –