Why <?php $a = 2; $b = $a++; echo $b; ?> is a=3 and b=2? | 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 $b; ?> is a=3 and b=2?

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

5th Jul 2017, 12:19 AM
Sandra Curo
Sandra Curo - avatar
3 Answers
+ 1
what that does is takes the value in a and adds 1 to it, then that is placed in the variable b. so a will, in this example stay the same. b equals 2 +1.
5th Jul 2017, 2:32 AM
James Barrow
James Barrow - avatar
0
Thanks 👍
7th Jul 2017, 4:09 AM
Sandra Curo
Sandra Curo - avatar
0
hope it helped?
7th Jul 2017, 4:10 AM
James Barrow
James Barrow - avatar