How to check if a string is one of the known values?

前端 未结 4 2019
长发绾君心
长发绾君心 2020-12-03 14:49

Suppose I have the code above, how to write th

4条回答
  •  孤城傲影
    2020-12-03 15:39

    Try this:

    if (in_array($a, array('are','abc','xyz','lmn')))
    {
      // Code
    }
    

    http://php.net/manual/en/function.in-array.php

    in_arrayChecks if a value exists in an array

    bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) Searches haystack for needle using loose comparison unless strict is set.

提交回复
热议问题