Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is |= 1

Status
Not open for further replies.

Glowball

Programmer
Oct 6, 2001
373
US
I saw someone use |= in their code but I can't find any reference to it in the manual. If I run this code it returns 1:

Code:
$myVar |= 1;
echo $myVar;

What does it mean? Thanks!
 
It's "bitwise or equals", and is equivalent to:

$myVar = $myVar | 1;

It basically toggles on the least significant bit of the original value.

Nearly every PHP operator can be used in a single operation with "=".


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks, I figured it was a bitwise thing but I couldn't find a reference!
 
There really isn't one. The only mention of the so-called "combined operators", liek +=, -=, etc is

PHP manual said:
In addition to the basic assignment operator, there are "combined operators" for all of the binary arithmetic and string operators that allow you to use a value in an expression and then set its value to the result of that expression.

which appears here


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top