+ 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 ?>

27th Jun 2019, 8:55 PM
Rowrowak đŸ‘€
Rowrowak đŸ‘€ - avatar
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.
28th Jun 2019, 1:48 AM
Alexander Santos
Alexander Santos - avatar
+ 1
Alexander Santos Thank you. It helped.
28th Jun 2019, 8:08 AM
Rowrowak đŸ‘€
Rowrowak đŸ‘€ - avatar