1

Well, I know | would means 'OR' in php; however, when I was trying to make it work with number, things go weired.

You may want to try the code below:

<?php 
    $i = 101;
    $i |= 7;
    echo $i; // output: 103 ?! why?!
?>
Narendrasingh Sisodia
  • 20,667
  • 5
  • 43
  • 53
Weijing Lin
  • 555
  • 2
  • 5
  • 15
  • What are you trying to do exactly? As aldrin stated, it's a bitwise OR, do you want a comparison OR - `$i || 7;`? – Darren Aug 17 '15 at 06:13

2 Answers2

0

It would convert into binary when you pass | to values. Please refer for more What Does Using A Single Pipe '|' In A Function Argument Do?

Explanation:

Decimal             Binary
101                 1100101
7                   111

OR (|) operation in these values:

64  32  16  8  4  2  1  =   Value
1   1   0   0  1  0  1  =   101
               1  1  1  =   7
-------------------------------
1   1   0   0  1  1  1  =   103
Community
  • 1
  • 1
Disha V.
  • 1,797
  • 1
  • 12
  • 20
0

Its a bitwise OR operator. Explanation:

Binary of 101 is: 01100101 and place values are: 64+32+4+1

Binary of 7 is: 111 and place values are: 4+2+1

Both values sets together will be: 64+32+4+2+1 = 103

amit
  • 864
  • 6
  • 16