【问题标题】:How to use operators so that they exclude zero?如何使用运算符使它们排除零?
【发布时间】:2012-03-18 00:19:52
【问题描述】:

在我的数据库中,我有“最大文件数”,但我想将其设置为 0 以表示无限制。

所以我需要一种方法

if ($count >= $max){
    //a value of 0 in $max should not be here
} else {
   //but here
}

这是可能的还是我必须为 0 创建一个排除项?

【问题讨论】:

    标签: php math operators


    【解决方案1】:
    if($max && ($count >= $max)) ....
    

    【讨论】:

    • 虽然这是一个更清晰的代码,但它没有自我记录。一个人必须花费超过 1 秒的时间来阅读这篇文章并用你的代码逻辑来理解这一篇(允许全部为 0)
    【解决方案2】:
    if (($max !== 0) && ($count >= $max) ){
    

    【讨论】:

      【解决方案3】:
      if (!empty($max) && $count >= $max ) { ...
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-30
        • 1970-01-01
        • 2014-12-16
        • 2014-12-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多