可能重复:
PHP - and/or keywords
Ruby: difference between || and 'or''and,or'和'&&,||'有什么区别?
是什么这之间的区别:
a=20
b=30
if (a > 10 && b > 10)
puts a
end
这:
if (a > 10 and b > 10)
puts a
end
也解释了“||”和“或”
可能重复:
PHP - and/or keywords
Ruby: difference between || and 'or''and,or'和'&&,||'有什么区别?
是什么这之间的区别:
a=20
b=30
if (a > 10 && b > 10)
puts a
end
这:
if (a > 10 and b > 10)
puts a
end
也解释了“||”和“或”
您可以在PHP的文档中阅读有关operators的文章。
答案涉及已被分配到这个问题PHP
标签,但是,事后又
删除它们与一个小的差别一样。与&&
和||
相比,and
和or
运营商具有lower precedence。
从manual拿这个例子:
// The result of the expression (true && false) is assigned to $g
// Acts like: ($g = (true && false))
$g = true && false;
// The constant true is assigned to $h and then false is ignored
// Acts like: (($h = true) and false)
$h = true and false;
你可以从优先级表中看到Ruby,差异也优先级,因为它是在PHP中: and
和or
的优先级低于&&
和||
。
但与PHP稍有不同:在Ruby中,and
和or
具有相同的优先级。
你为什么这个标签作为PHP?我删除了PHP标记,并将Rails标记更改为Ruby,因为代码示例是Ruby(或无效的PHP:P)。这里有很多答案都是关于PHP的。我对此感到抱歉。 (虽然这两种语言的答案都是一样的。) – 2011-04-04 11:14:24
由于您标记了[[PHP]],并且所有当前答案都链接到PHP文档,因此我将其标记为[PHP]的完全重复并且/或关键字](http://stackoverflow.com/questions/4502092/php-and-or-keywords),你会发现完全相同的答案。 – 2011-04-04 11:15:57
我找到了我的问题的答案。我已经发布了下面的答案。请检查一下。谢谢大家。 – 2011-04-04 12:06:32