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

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

Suppose I have the code above, how to write th

4条回答
  •  -上瘾入骨i
    2020-12-03 15:50

    There is in_array function.

    if(in_array($a, array('are','abc','xyz','lmn'), true)){
       echo 'true';
    }
    

    NOTE: You should set the 3rd parameter to true to use the strict compare.

    in_array(0, array('are','abc','xyz','lmn')) will return true, this may not what you expected.

提交回复
热议问题