Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using |= in php

Tags:

equality

php

I was reading some php code source and found the following:

$failed |= is_numeric( $key );

Other than if $key is numeric , what does |= mean?

like image 609
Tarek Avatar asked Jul 06 '11 14:07

Tarek


1 Answers

$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

like image 53
Spudley Avatar answered Oct 03 '22 14:10

Spudley