As most of other operator groups in PHP, these increment and decrement operators are also self-explanatory; the increments increase the numeric value of a variable while the decrements decrease it.

The example below shows a few ways of using increment and decrement operators.

Example of increment and decrement operators in PHP

    $a = 10;
    ++$a; // Pre-Increment; will increase $a by one and return 11
    $a++; // Post-Increment; returns $a and then increases it by 1
    --$a; // Pre-Decrement; will decrease $a by one and return 9
    $a--; // Post-Decrement; returns $a and then decreases it by 1

In the example above you can notice that a variable can have an operator in front of itself, or behind of itself. The difference is that one with an operator in front will first execute the increment ot decrement operation and return the result after calculation, while during other situation it will first return the value as is, and then execute the operation.


›› go to examples ››