AND [和] && 之间的区别
鉴于以下陈述:
if($value && array_key_exists($value, $array)) {
$hello['world'] = $value;
}
最好使用逻辑运算符 AND 与 && 相对?
Given the statement:
if($value && array_key_exists($value, $array)) {
$hello['world'] = $value;
}
Would it be best to use the logical operator AND as opposed to &&?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
他们自己也做同样的事情。所以
a && b
的含义与a 和 b
相同。但是,它们并不相同,因为&&
的优先级高于and
。有关更多信息,请参阅文档。此示例显示了差异:
On their own, they do exactly the same. So
a && b
means the same thana and b
. But, they are not the same, as&&
has a higher precedence thanand
. See the docs for further information.This example here shows the difference:
您提供的链接有一个注释:
在您的情况下,由于它是唯一的运算符,因此取决于您,但它们并不完全相同。
The link you provide has a note:
In your case, since it's the only operator, it is up to you, but they aren't exactly the same.
它们在条件语句中是相同的,但在条件赋值时要小心:
并且
来自逻辑运算符 您链接到的手册。
They are the same in conditional statements, but be careful on conditional assignments:
and
From the Logical Operators manual you linked to.
唯一的拼写差异..使用 && 而不是 AND 或 and 是一个很好的做法..
only difference of spelling..its a good practice to use && instead of AND or and..