php increment and decrement 1

php increment and decrement

// Php increment and decrement: Just print it then understand
$n =9;

echo $n++;
echo PHP_EOL;
echo ++$n;
echo PHP_EOL;
echo --$n;
echo PHP_EOL;
echo $n--;
echo PHP_EOL;

echo "Another Example======\n";


$a = 7;
$b = $a++;

echo $b."\n".$a;

Here is what the above code is Doing:
1. $a = 7;
2. $b = $a++;
3. echo $b.”\n”.$a;

So, first $a is assigned 7.
Then $b is assigned $a++.

$a++ is a post-increment operator.

So, $b is assigned 7, and then $a is incremented to 8.

Then, $b and $a are printed.

Similar Posts