繁体   English   中英

您将如何遍历100个名称的列表,以检查某个条目不是PHP中的那些值之一?

[英]How would you loop through a list of 100 names to check that a certain entry is not one of those values in PHP?

我有一个确定的输入,即当用户输入一个单词时,需要对照100个单词的列表进行检查。 我将如何最轻松地遍历这些单词? 我应该使用大量数组吗?

如果您不关心区分大小写或错别字,这是最简单的方法:

$word = 'foo';
$wordList = array('foo', 'bar', 'baz', ...);
$wordIsInWordList = in_array($word, $wordList);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM