1

Possible Duplicates:
Reference - What does this symbol mean in PHP?
What is the difference between the | and || operators?

Just bumped into this line of code, and I was wondering what is the difference between these two case:

The person who did this do not remember what was the meaning, but it was important.

...
if ($condition1 | $condition2) {
...
...
if ($condition1 || $condition2) {
...
Community
  • 1
  • 1
yvoyer
  • 7,476
  • 5
  • 33
  • 37
  • 1
    See [Reference - What does this symbol mean in PHP?](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – BoltClock Mar 22 '11 at 16:01
  • http://stackoverflow.com/questions/2233835/what-is-the-difference-between-the-and-operators – Elzo Valugi Mar 22 '11 at 16:02
  • http://php.net/manual/en/language.operators.php – Marc B Mar 22 '11 at 16:02
  • I tried to search for `operator` and `|` before asking the question, but didn't found anything (since I didn't know the term to use (bitwise operator). The question can be deleted, thanks. – yvoyer Mar 22 '11 at 16:19
  • @yvoyer: As a general tip, you can visit `php.net/whatever` and PHP will translate the whatever into a search for that term. The operators URL I posted above was the result of hitting `php.net/operator` – Marc B Mar 22 '11 at 16:25

3 Answers3

2

| = bitwise or

|| = boolean or

osm
  • 4,186
  • 3
  • 23
  • 24
1

| is a bitwise or, || is a logical or. | operates on binary values whereas || operates on boolean ones.

E.g. 5 | 3 is 0101 OR 0011 which is 0111 which is 7, whereas True || False is True and False || False is False.

Rafe Kettler
  • 75,757
  • 21
  • 156
  • 151
0

| is the bitwise-OR-operator while || is the logical-OR-operator.

Florian Greinacher
  • 14,478
  • 1
  • 35
  • 53