1

I saw this operator |= in another question and I wondered what it does. It looks like this:

 $result |= (ord($safe[$i % $safeLen]) ^ ord($user[$i]));
Rene Pot
  • 24,681
  • 7
  • 68
  • 92
Moises Zermeño
  • 763
  • 1
  • 6
  • 18

1 Answers1

4

It's just a combined operator: assignment(=) and a OR operator(|). It's the same as:

$result = $result | (ord($safe[$i % $safeLen]) ^ ord($user[$i]));

Bitwise OR(inclusive) operator |:

  a  |  b  |  result
---------------------
  0  |  0  |   0
  1  |  0  |   1
  0  |  1  |   1
  1  |  1  |   1

Bitwise XOR(exclusive) operator ^:

  a  |  b  |  result
---------------------
  0  |  0  |   0
  1  |  0  |   1
  0  |  1  |   1
  1  |  1  |   0
Rizier123
  • 58,877
  • 16
  • 101
  • 156
  • 2
    Seems like it ought to feature on [this question](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – James Thorpe Feb 12 '15 at 17:05