如何检查字符串是否为已知值之一? [英] How to check if a string is one of the known values?
本文介绍了如何检查字符串是否为已知值之一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?php
$a = 'abc';
if($a among array('are','abc','xyz','lmn'))
echo 'true';
?>
假设我有上面的代码,如何编写语句"if($ a between ...)"? 谢谢
Suppose I have the code above, how to write the statement "if($a among...)"? Thank you
推荐答案
使用 in_array()
函数.
手册说:
除非使用严格的比较,否则使用宽松的比较在干草堆中搜索针.
Searches haystack for needle using loose comparison unless strict is set.
示例:
<?php
$a = 'abc';
if (in_array($a, array('are','abc','xyz','lmn'))) {
echo "Got abc";
}
?>
这篇关于如何检查字符串是否为已知值之一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文