PHP Auto-Increment and Auto-Decrement Operators
Posted by Daniel at 6:16 am
The auto-increment operator designed to automatically increment the value of the variable it is attached to by 1. It is represented by a double addition symbol (++). To see it in action, run the following script:
<?php // define $total as 10 $total = 10; // increment it $total++; // $total is now 11 ?>
Thus, <?php $total++; ?> is functionally equivalent to <?php
$total = $total + 1; ?>.
There’s also a corresponding auto-decrement operator (––), which does exactly the opposite:
<?php // define $total as 10 $total = 10; // decrement it $total--; // $total is now 9 ?>
These operators are frequently used in loops to update the value of the loop counter.