The -= operator is a simplified way of writing I want to decrease the variable by a certain value. It’s called the subtraction-assignment operator.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $i = 10; $i-=1; echo $i; // outputs 9; $i = 10; $i-=5; echo $i; // outputs 5 $i=10; $i-= -10; echo $i; // output 20 (since 10 - (-10) is the same as 10+10; $i=10; $i-=$i; echo $i; // output 0; |
Find out more
- MSDN page about the subtraction assignment for JScript
- Google search for “subtraction-assignment”
- A post by me: Operator precedence – what does
(i=1)*i-- - --i*(i=-3)*i++ + ++iequal and why? (not for beginners)
