|= Operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • osirishinzen

    |= Operator

    I'm a total newbie in PHP. While studying code a friend showed me I
    was puzzled by this operator " |= " (quotes not included). I know it
    is somesort of operator but I could not find a description of it in
    the php documentation. What does it do and what is it for ? Many
    thanks.....
  • Tom Thackrey

    #2
    Re: |= Operator


    On 24-Dec-2003, osirishinzen@ho tpop.com (osirishinzen) wrote:
    [color=blue]
    > I'm a total newbie in PHP. While studying code a friend showed me I
    > was puzzled by this operator " |= " (quotes not included). I know it
    > is somesort of operator but I could not find a description of it in
    > the php documentation. What does it do and what is it for ? Many
    > thanks.....[/color]

    It's the combination of logical or and assignment
    $a |= $b;
    is equivalent to
    $a = $a | $b;

    +=, -=, .=, etc all work the same way

    --
    Tom Thackrey

    tom (at) creative (dash) light (dot) com
    do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

    Comment

    • Matthias Esken

      #3
      Re: |= Operator

      osirishinzen@ho tpop.com (osirishinzen) schrieb:
      [color=blue]
      > I'm a total newbie in PHP. While studying code a friend showed me I
      > was puzzled by this operator " |= " (quotes not included). I know it
      > is somesort of operator but I could not find a description of it in
      > the php documentation.[/color]

      Looks like a merger of the bitwise comparison operator
      (http://www.php.net/manual/en/languag...rs.bitwise.php) and an
      assignment.
      [color=blue]
      > What does it do and what is it for ?[/color]

      $i = 5;
      $i |= 9;
      echo($i);

      "|" works bitwise. 5 has set the bits for 1 and 4, 9 has set the bits
      for 1 and 8. This data is "or"ed and we get a result of 13.

      Regards,
      Matthias

      Comment

      Working...