可能重複:
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