The reason for that behavior is the parentheses. From the description:

"Parentheses may be used to force precedence, if necessary. For instance: (1 + 5) * 3 evaluates to 18."

So the order of operations says that even though the equality operator has higher precedence, the parentheses in your statement force the assignment operator to a higher precedence than the equality operator.

That said, it still doesn't work the way you expect it to. Neither way works, for these reasons:

<?php

if ( $a != ($a = $b) )

?>

Order of operations says to do the parentheses first. So you end up with:

<?php

$a = $b;

if ( $a != $a )

?>

Which is obviously going to be false. Without the parentheses:

<?php

if ( $a != $a = $b )

?>

Order of operations says to do the inequality first, then the assignment, so you have:

<?php

if ( $a != $a );

$a = $b;

?>

Which again is not what you expected, and again will always be false. But because you are only working with values of 0 and 1, you can make use of the XOR operator:

<?php

if ( $a ^= $b )

?>

This will only be true if 1) $a is 0 and $b is 1, or 2) $a is 1 and $b is 0. That is precisely what you wanted, and it even does the assignment the way you expected it to.

<?php

foreach ($ourstring as $c) {

if ($bold ^= $c['bold']) $resstring .= bold;

if ($underline ^= $c['underline']) $resstring .= underline;

$resstring .= $c[0];

}

?>

That code now works and produces the output you expected.

**Assignment Operators : PHP - PHP Tutorials - c4learn.com**

## Comments

## Qegemelifofim

12-05-2017 22:35 Comments

Lois Lerner and John Kosiken R just 2 Operators w/were victimized by. The Tip of the Iceberg. and

## Qivujaroyotaf

13-05-2017 23:53 Comments

Come to think of it, I also trust used car salesmen and 3 card monte operators more than the President.

## Ziviwoyiyayo

14-05-2017 19:40 Comments

Estate Agents are a professional that people will remember in the future like we think of Lamp Lighters or Switchboard Operators

## Woholowa

15-05-2017 08:18 Comments

In 2016, there were 271, 935 farm operators with an average age of 55.0 years.

## Murozakakag

13-05-2017 17:18 Comments

Taking small bites of big data Operators pick the right tools to manage food cost

## Ceroqacu

10-07-2017 15:30 Comments

US fantasy operators push the boundaries of legal sports betting

## Yoqozaqes

01-09-2017 17:34 Comments

: files misdemeanor charges against operators of after-hours club where resident was shot and killed.