【问题标题】:PHP if (not multiple values) not working? [duplicate]PHP if(不是多个值)不起作用? [复制]
【发布时间】:2015-02-26 20:45:08
【问题描述】:

如果变量不匹配 5 个不同的值,我想使用一些简单的代码来退出脚本。我只能让它与一个一起工作。即使 URL 变量匹配,脚本也会不断回显“未知请求”。

//Make sure the value of the variable matches one of the variables in the URL.
if($category !== ('food' || 'drink' || 'etc.'))
{echo "unknown request.";
exit();
}

谢谢。

【问题讨论】:

    标签: php


    【解决方案1】:

    您必须比较每个值。另外,你想要 AND &&:

    if($category !== 'food' && $category !== 'drink' && $category !==  'etc.')
    

    或者使用数组:

    if(!in_array($category, array('food', 'drink', 'etc.'))
    

    【讨论】:

      猜你喜欢
      • 2018-12-02
      • 1970-01-01
      • 2014-08-16
      • 2017-04-27
      • 2017-09-18
      • 1970-01-01
      • 1970-01-01
      • 2016-04-15
      • 2014-11-07
      相关资源
      最近更新 更多