0

Increment & Decrement

Hello Friends! Learning PHP with Solo Learn. I have some doubts to understand the increment & decrement. Kindly help me! $a = 2; $b = $a++; // $a=3, $b=2 $a = 2; $b = ++$a; // $a=3, $b=3 Thanking you. Keshav Murthy

23rd Feb 2017, 5:20 PM
Keshav Murthy
Keshav Murthy - avatar
2 Réponses
+ 20
Let's say we have $y = ++$x X is incremented then it is assigned to the y. If we have $y = $x++, x is assigned to y, then it is incremented... $x = 3 $y = $x++ // $y is 3, then x is incremented so $x = 4 $x = 3 $y = ++$x // $x is incremented so, $x = 4. Then it is assigned to y, so $y = 4 It works the same for the decrementing! Hope this makes sense! 😃😄
23rd Feb 2017, 5:27 PM
Gami
Gami - avatar
+ 1
@Gami Thank you so much Sir! Well explained.....😃😇
26th Feb 2017, 3:26 PM
Keshav Murthy
Keshav Murthy - avatar