我想寻找一个字符串,并得到相关的值,但在测试中的功能,在各次搜索词(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 –