Subscriber only lesson.
Sign up to this course to view this lesson.
Increment operators allow us to increase or decrease a number by 1.
When to use
Whenever you want to increase or decrease a number by just 1, use an increment operator.
These are the increment operators:
$num++; Output the variable then increment
$num--; Output the variable then decrement
++$num; Increment the variable then output it
--$num; Decrement the variable then output it
Where you put your ++ or -- is important. Put them before the variable to increment/decrement and then output. Put them after to output first, then increment/decrement.
Hints & tips
- Increment operators allow you to increase or decrease a number by 1.
- putting them before or after the variable matters!
Lesson notes are only available for subscribers.