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 Answers

+ 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.....ðŸ˜ƒðŸ˜‡

Hot today

Unable to overload +

2 Votes

Hey! [SOLVED]

0 Votes

Pls rectify the errors.

1 Votes

Python list half printed

0 Votes

Find the error please.

0 Votes