【问题标题】:if condition of in_array to boolean如果 in_array 的条件为布尔值
【发布时间】:2012-02-23 17:31:17
【问题描述】:

所以我有一个 in_array 检查,称为

if (in_array('pageLevel',$userlevels))

我想连接一个布尔值,比如$hasAccess,这样我就可以申请了

if ($hasAccess == true) { do something }

我试过if (in_array('pageLevel',$userlevels)) { $hasAccess == true }

但这似乎不起作用。谁能告诉我如何使用这个?

【问题讨论】:

    标签: php arrays string boolean


    【解决方案1】:

    $hasAccess == 真

    应该是$hasAccess = true。或者

    $hasAccess = in_array('pageLevel',$userlevels);
    

    【讨论】:

    • if (in_array('pageLevel',$userlevels)) { $hasAccess = true; } if ($hasAccess) { dosomething } 就像一个魅力!谢谢大家,我确实混淆了运营商。
    【解决方案2】:

    试试$hasAccess = true; 你需要赋值给变量(=),而不是仅仅比较它(==)然后把结果扔掉。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-15
      • 2013-02-21
      • 2017-01-10
      • 1970-01-01
      • 2013-03-21
      • 2015-07-03
      相关资源
      最近更新 更多