- PHP

How to increment in PHP

You can increment a variable with ++.

$i++;

Example 1:

<?php

$i = 1;

$i++;

echo $i;

?>

Output: 2

Example 2:

<?php

$i = 'a';

$i++;

echo $i;

?>

Output: b

Example 3:

<?php

$i = 1;

while ($i <= 5) {
    echo $i . '<br>';

    $i++;
}

?>

Output:

1
2
3
4
5