这取决于你的意思。
mysql_result在失败时返回FALSE
,如果您指定了无效(行、字段),就会发生这种情况。要检查这一点,您需要使用相同性运算符===
,它会检查值和类型。相等运算符==
、empty()
函数和 if 语句的条件评估都检查值但不检查类型。
这意味着使用其中一种方法,所有等同于 的各种值之间没有区别Boolean FALSE
,例如空字符串、空数组、字符串'0'
和值NULL
。
因此,如果您想真正彻底地了解它,您可以执行以下操作:
if ($description === FALSE) {
throw new Exception("The row $i was out of range in query $query.");
} else if ($description === NULL) {
// assuming that the description field has a default value of NULL
// * this one I'm not sure about.. the documentation for mysql_result claims
// that it returns a string, so this may never happen.
// It's left as an exercise for the reader.
throw new Exception("Uninitialized value in result row $i of db query $query");
} else if ($description === '') {
echo "No description available";
} else {
echo $description;
}
由于在一组类似的条件下empty()
返回与 的等式 ( ) ,因此在结果可能实际为 的情况下,在类型检查中更严格的这一点尤其重要。 true
==
FALSE
"0"
显然我不允许发布多个超链接,因此我无法链接到比较运算符的文档(“ http://php.net/manual/en/language.operators.comparison.php ”)或空函数(“ http://php.net/empty ”)。幸运的是,他们的安全性相对宽松。呜呜!