Let's take a look at a question first:
<?php
$a = 1;
$b = $a + $a + +; Results: $a =2, $b =3
This problem is not difficult, obviously in PHP + + priority is higher than +, so first execute $a + +, when the $a value is 2
Look at one more question:
<?php
$a = 1;
$b = $a + $a + $a + +;
How much should $b be worth?
The answer is: 3
Why is it still 3? is the priority ratio + + higher than + +? After executing $a + +, the $a value should be 2, and the result is 5.
In fact, this is the correct answer is 3, at first I think it should be 5.
Explain:
The operator is combined from the left to the right, and the expression above is equivalent to
$ = ($a + $a) + $a + +
According to the principle of the left Union
Calculate $a + $a first
$b = 2 + $a + +;
It's time to compare + and + + operator precedence.
$b = 2 + 1; Then $a = 2
This is all a pain in the PHP pen test questions, in the actual project code should use parentheses to avoid these problems appear.