Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Decrement (--)

Subtract one from an integer counter.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

--$value
$value--

Subtract one from an integer counter. Prefix notation produces the updated value; postfix notation produces the previous value and still updates the variable. This difference matters when using the expression as an index. Keep separate changes in separate statements so their evaluation order is clear. In PHP 8.4 floats decrease and numeric strings become numbers. The string "AA" stays unchanged with E_DEPRECATED, while the empty string becomes integer −1 with E_DEPRECATED. Booleans and null remain unchanged with E_WARNING.

--$value
$value--
[4,2,2]

Examples

<?php
$position = 4;
$old = $position--;
$new = --$position;
echo json_encode([$old,$new,$position]);

Result

[4,2,2]

Sources