Why <?php $a = 2; $b = $a++; echo $a; ?> is a=3 and b=3 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why <?php $a = 2; $b = $a++; echo $a; ?> is a=3 and b=3

I don't understand the result in this exercise. Result: $a=3, $b=3

5th Jul 2017, 12:23 AM
Sandra Curo
Sandra Curo - avatar
3 Answers
+ 4
a=3 but b=2 because in $b=$a++ first b is set to the value of a , then a would be incremented. here you should know the difference of pre-increment and post-increment
5th Jul 2017, 3:13 AM
Saeede
Saeede - avatar
+ 3
$a is 3 but i think $b is 2
5th Jul 2017, 12:48 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
0
Thanks 👍
7th Jul 2017, 4:09 AM
Sandra Curo
Sandra Curo - avatar