Increment in PHP

Find this useful? Support us: Star on GitHub 6
Category: Number | Language: PHP

To increment a number in PHP, you can use the ++ operator.

Here's an example code snippet:

$num = 5;
$num++;

echo $num; // outputs 6

In this example, the variable $num is initially assigned a value of 5. The ++ operator is then used to increment the value of $num by 1. The resulting value of $num is 6, which is then output using the echo statement.

You can also use the += operator to increment a number by a specific value. Here's an example:

$num = 5;
$num += 3;

echo $num; // outputs 8

In this example, the += operator is used to increment the value of $num by 3. The resulting value of $num is 8, which is then output using the echo statement.