Reputation: 3798
I was reading some php code source and found the following:
$failed |= is_numeric( $key );
Other than if $key
is numeric , what does |=
mean?
Upvotes: 12
Views: 506
Reputation: 168695
$x |= $y;
is the same as $x = $x | $y;
$x | $y
is a bitwise operator which means it returns the result of a logical 'or' between the two variables.
In the context of the question, it allows $failed
to store failure statuses for several actions in a single variable (each bit position representing an individual action).
If you need to know more about what this does, I suggest reading the PHP manual page for bitwise operators: http://www.php.net/manual/en/language.operators.bitwise.php
Upvotes: 14
Reputation: 83622
That's a bitwise OR
so the line is the same as
$failed = $failed | is_numeric($key);
That means $failed
is true
if either $failed
has been true
before or is_numeric($key)
is true
.
Upvotes: 4
Reputation: 360702
It's the equivalent of:
$failed = $failed | is_numeric($key);
|
is the bitwise or
operator.
Anytime you see x <something>= y
, it can be rewritten as x = x <something> y
, pretty much.
Upvotes: 4
Reputation: 17356
The notation $a |= $b
means $a = $a | $b
, similar to other x=
notations. The |
is a bitwise OR operation.
Upvotes: 12