Sobes.tech
Intern

What is a decrement?

sobes.tech AI

Answer from AI

Decrement is an operation that decreases the value of a variable by one.

In PHP, there are two types of decrement operators:

  • Postfix decrement ($var--): Returns the original value of the variable, then decreases it by one.
  • Prefix decrement (--$var): Decreases the value of the variable by one, then returns the new value.

Example:

<?php
$a = 5;
$b = $a--; // $b equals 5, $a becomes 4
$c = 5;
$d = --$c; // $d equals 4, $c becomes 4
?>