Can someone better explain increment/decrement operators? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone better explain increment/decrement operators?

ok so i know that $var++ means $var=$var+1 but if you like say: $var1=1; $var2=$var1++; why is it turning into var1 having the value of 2 and var 2 having the value of 1? is it assigning the value of var1 to var2, then increments it?

24th Feb 2017, 6:24 PM
Toni Pop
Toni Pop - avatar
2 Answers
+ 2
yes, correctly.
24th Feb 2017, 6:36 PM
Mario L.
Mario L. - avatar
+ 1
$var2=$var1++; here 2 operators are used one is assignment (=) which is used to assign the value of var1 to var2 and then second operator(++) is used to increment the var1 value. there are 2 types of increment operator 1. post increment(var++) which will increment after the operation completed.(means first assign the value then increment) 2.Pre increment(++var) which will increment first and then complete the operation
24th Feb 2017, 7:02 PM
ashutosh mishra
ashutosh mishra - avatar