• The increment operators are used to increment a variable's value.
• The decrement operators are used to decrement a variable's value.
$x++; // equivalent to $x = $x+1;
$x--; // equivalent to $x = $x-1;
• Increment and decrement operators either precede or follow a variable.
$x++; // post-increment
$x--; // post-decrement
++$x; // pre-increment
--$x; // pre-decrement
• The difference is that the post-increment returns the original value before it changes the variable,
while the pre-increment changes the variable first and then returns the value.
For instance:
$a = 2; $b = $a++; // $a=3, $b=2
$a = 2; $b = ++$a; // $a=3, $b=3
$a = 2; $b = $a--; // $a=1, $b=2
$a = 2; $b = --$a; // $a=1, $b=1