+ 1
The difference between $a+$a++ and $a+$b++
What's the difference between these two? Why their outputs are different? <?php $a = 3; echo $a + $a++; // 7 $c = 3; $d = 3; echo $c + $d++; // 6 ?>
2 Answers
+ 2
The evalution. When same using same var, it recognizes that you can.just sum up (3+3)and increment.
But with different vars, the evaluation is made this way
A temp var is created with the size of an int
$ is read, so it expands next variable
c value is given to the temp var
plus signal is read, so next var will be sum with c
$ again
d is found, sum up with c and add to the temp var
increment d
So d isn't returned to the temp var.
+ 1
Alexander Santos Thank you. It helped.