I'm reading other's php code, and there's one line writes:
if ($isprivate)
{
$status |= STATUS_PRIVATE;
}
I have no idea what does "|=" mean? Can anyone help on it?
I'm reading other's php code, and there's one line writes:
if ($isprivate)
{
$status |= STATUS_PRIVATE;
}
I have no idea what does "|=" mean? Can anyone help on it?
| is a bitwise operator. It takes two numbers and conducts a bitwise OR operation. http://en.wikipedia.org/wiki/Bitwise_OR#OR
Ex: A = 4 B = 3
In binary: A = 100 B = 011
A | B == 111 (in binary) == 7 (in decimal)
A |= B is the same as A = A | B
In your specific example, the code is checking to see if $isPrivate is true. If it is, it makes the bit marked by STATUS_PRIVATE set to TRUE in the $status variable.
This is a shorthand of this:
$status = $status | STATUS_PRIVATE;
For example
define(STATUS_PRIVATE, 0b01);
$status = 0b00;
$status |= STATUS_PRIVATE; //status become 0b01;