【问题标题】:cakephp !empty and isset difference?cakephp !empty 和 isset 的区别?
【发布时间】:2011-08-01 08:42:09
【问题描述】:

我正在使用以下代码检查变量

if(!empty($var) && $var == 1)
{
       // do some thing
}
elseif(!empty($var) && $var == 0)
{
       // do some thing
}

但是 elseif 不起作用 如果我删除了 !empty 那么它的工作正常。 那是什么问题

谁能解释一下这些以及 isset 和 !empty 之间的区别

【问题讨论】:

    标签: php cakephp-1.3 cakephp-1.2


    【解决方案1】:

    请仔细阅读the documentation,了解 PHP 认为是什么empty

    我会将您的代码重写为:

    if (isset($var)) {
        if ($var == 1) {
            ...
        } else if ($var == 0) {
            ...
        } else {
            // if you're that specific you should handle any other case as well
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-02
      • 2017-04-11
      • 1970-01-01
      • 2011-11-03
      • 2010-12-29
      • 1970-01-01
      相关资源
      最近更新 更多