Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pre-increment

Pre-increment is the ++ operator, used on a variable, when it is placed before the variable. This means that the increment happens before the variable is read: in this case, the first echo displays 2, as the increment happens before the echo call.

There is also a pre-decrement, which uses the operator --, and reduces the variable of 1.

Pre-increment and pre-decrement have a corresponding post-increment and post-decrement.

<?php

    $a = 1;
    echo ++$a; // displays 2
    echo $a;   // displays 2

?>

Documentation

See Also