Check if word is inside a group of words
This question already has an answer here:
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
http://php.net/manual/en/function.in-array.php
You can combine the in_array and explode functions
echo ((in_array($searchTerm, explode(",", $cities)))?"Yes":"No");
or if you want a more readable version
$resultArray = explode(",", $cities);
$result = (in_array($searchTerm, $resultArray);
if ($result) {
echo "Yes"
} else {
echo "No";
}
链接地址: http://www.djcxy.com/p/13126.html
下一篇: 检查单词是否在一组单词中