簡體   English   中英

php沒有返回false的值

[英]php not returning value of false

回到這里我無法得到錯誤的價值。 真值返回正常。 我錯過了什么?

if ((count($this->_brokenRulesCollection)) == 0)  {
    return true;
} else {
    return false;
}

在PHP中,轉換為字符串時為false是空字符串, true轉換為字符串為“1”。

使用var_dump而不是echo進行調試。

如果數組$this->_brokenRulesCollection不為空,則代碼可以返回false

如果$this->_brokenRulesCollection不是數組或具有已實現Countable接口的對象,則count($this->_brokenRulesCollection)將返回1。

在條件表達式中(除非使用類型匹配運算符===或!==),任何非零整數等於true,任何非零長度字符串等效於true,相反,零或空字符串為false。

所以

if ((count($this->_brokenRulesCollection)) == 0)  {
   return true;
} else {
  return false;
}

可以寫成:

return count($this->_brokenRulesCollection);

C。

如果您確實想要看到“false”,請在返回之前將值放入變量中。 因此:

if ((count($this->_brokenRulesCollection)) == 0)  {
    $value=true;
} else {
    $value=false;
}
return $value;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM