Search code examples
phparraysloopsblacklist

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


I have a certain input that when the user enters a word in needs to be checked against a list of 100 words. How would I loop through these words the easiest? Should I use a massive array?


Solution

  • If you don't care about case sensitivity or typos, this is the most straight-forward way:

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