2013-06-21 50 views
0

在文档http://www.php.net/manual/en/language.operators.precedence.php据说,++--运算符具有很高的优先级。 但据我所知,++$x$x++是不一样的。此外,$x++应该有最小的优先级,因为一切都完成后其计算公式为:PHP post-increment/descrement运算符优先级

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

所以,后递增/递减运算应该在这个表中的底部?

+0

这就是为什么我从来没有在任何语言编写这样的代码,无论是:) –

+0

@佐尔坦 - 陶马希我是多么紧凑将要进行ZCE考试,所以我需要知道这一点。在现实生活中,普通人永远不会这样做:) – avasin

回答

2

是的。如果操作符被放置在变量之前,那么变量在任何其他操作顺序之前被改变。

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

当运营商在前面时,它优先于所有其他运营商。 您可以在以下网站一个简单的解释,以及:

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