使用逻辑或设置变量
$db_hased_pw = $result["password"] || false;
我理解这行代码的用法,但是什么时候它会评估为 false?
仅当 $result["password"]
未定义时,$db_hased_pw
才等于 false 吗?
或者如果 $result["password"]
未设置、或 false、零或 null,则 $db_hased_password
是否设置为 false?
$db_hased_pw = $result["password"] || false;
I understand the usage of this line of code, but WHEN will it evaluate as false?
will $db_hased_pw
equal false only when $result["password"]
is undefined?
or is $db_hased_password
be set to false if $result["password"]
is unset, or false, or zero, or null?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当 $result["password"] 是“假值”时,它将计算为 false。
empty
上的页面描述了这些值。这些是等效的:
如果
$result["password"]
确实可以是未定义的,您应该使用:以避免通知。
It will evaluate to false when
$result["password"]
is a "falsy value". The page onempty
describes these values.These would be equivalent:
If
$result["password"]
can indeed be undefined, you should be using:to avoid a notice.
来自 PHP 文档:
当转换为布尔值时,以下值被视为 FALSE:
您可以在 此页面。
From PHP documentation:
When converting to boolean, the following values are considered FALSE:
You can read more on this page.