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
2 Respostas
+ 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! 😃😄
+ 1
@Gami
Thank you so much Sir!
Well explained.....😃😇