逻辑运算符,||还是OR? [英] Logical Operators, || or OR?

查看:107
本文介绍了逻辑运算符,||还是OR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我记得有一阵子关于逻辑运算符的内容,在OR的情况下,使用||or更好(反之亦然).

I remember reading a while back in regards to logical operators that in the case of OR, using || was better than or (or vice versa).

当我回到项目中时,我只需要在项目中使用它,但是我不记得建议使用哪个运算符,甚至是真的.

I just had to use this in my project when it came back to me, but I can't remember which operator was recommended or if it was even true.

哪个更好,为什么?

推荐答案

没有更好"的选择,但更常见的是||.它们具有不同的 优先级 ||会像人们通常期望的那样工作.

There is no "better" but the more common one is ||. They have different precedence and || would work like one would expect normally.

另请参见: 逻辑运算符 (以下示例是从此处获取的):

// The result of the expression (false || true) is assigned to $e
// Acts like: ($e = (false || true))
$e = false || true;

// The constant false is assigned to $f and then true is ignored
// Acts like: (($f = false) or true)
$f = false or true;

这篇关于逻辑运算符,||还是OR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆