Skip to content
PHP Logo

What does the ++ operator do in PHP and how is it used?

The ++ operator in PHP is used to increment the value of a variable by 1. It is a shorthand way of writing $variable = $variable + 1. This operator can be used in both pre-increment (++$variable) and post-increment ($variable++) forms.

php
$variable = 5;
$variable++; // Increment $variable by 1
echo $variable; // Output: 6