Junior
What is the difference between postfix increment and postfix decrement?
sobes.tech AI
Answer from AI
The difference in operation order and return value:
- Postfix increment (
$i++): First returns the current value of the variable, then increases it by 1. - Postfix decrement (
$i--): First returns the current value of the variable, then decreases it by 1.
Example:
<?php
$a = 5;
$b = $a++; // $b will be 5, $a will become 6
$c = 5;
$d = $c--; // $d will be 5, $c will become 4
| Operation | Action | Return value |
|---|---|---|
| Postfix increment | Return value first, then increment | Value before increment |
| Postfix decrement | Return value first, then decrement | Value before decrement |