2011-03-22 89 views
1

可能重複:
Reference - What does this symbol mean in PHP?
What is the difference between the | and || operators?Php:|有什麼區別?和||運營商

就撞上了這行代碼,我想知道的是這兩個案例的區別:

的做這個的人不記得是什麼意思,但這很重要。

 
... 
if ($condition1 | $condition2) { 
... 
 
... 
if ($condition1 || $condition2) { 
... 
+1

請參見參考 - 此符號在PHP中的含義是什麼?(http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – BoltClock 2011-03-22 16:01:19

+0

http://stackoverflow.com/questions/2233835/what-is-the-difference-between-the-and-operators – 2011-03-22 16:02:00

+0

http://php.net/manual/en/language.operators.php – 2011-03-22 16:02:21

回答

1

|bitwise or||是邏輯或。 |對二進制值進行操作,而||對布爾值進行操作。

E.g. 5 | 30101 OR 00110111是7,而True || False爲True,並且False || False爲False。

0

|是按位或運算符,而||是邏輯或運算符。

2

| = 按位

|| = 布爾值