0

In documentation http://www.php.net/manual/en/language.operators.precedence.php it is said, that ++ and -- operators have very high precedence. But as i know, ++$x and $x++ is not the same. Moreover, $x++ should have minimal precedence, because it is calculated after everything is done:

$x = 1;
var_dump(1 and $x--); // and operator is one of last operators in the table, it will be executed before post decrement

So, post- increment/decrement operators should be in this table in the bottom?

avasin
  • 9,186
  • 18
  • 80
  • 127

1 Answers1

3

Yes. If the operators are placed before the variable then the variable is changed before any other order of operations.

$a=4;
$x=++$a + 6; will result in $x=11 and $a=5
$x=$a++ + 6; will result in $x=10 and $a=5

When the operators are in front it takes precedence over all other operators. You can find a simple explanation at the following site as well:

http://www.php.net/manual/en/language.operators.increment.php

TwoEyedDan
  • 152
  • 1
  • 12