TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
-- operator is a unary arithmetic operator known as the decrement operator. It reduces the numeric value of a variable by exactly one. It modifies the operand in place and evaluates to either the original or the newly decremented value, depending on its syntactical placement relative to the variable.
The operator operates in two distinct modes based on its position:
1. Pre-decrement (--$variable)
The operator is placed before the operand. PHP decrements the variable by one before evaluating the expression. The operation returns the newly decremented value.
2. Post-decrement ($variable--)
The operator is placed after the operand. PHP evaluates the expression using the variable’s current value, and then decrements the variable by one after the evaluation is complete.
Type Handling and Coercion
The-- operator exhibits specific behaviors when applied to non-integer data types:
- Floats: Decrements the floating-point value by exactly
1.0. For example,5.5becomes4.5. - Numeric Strings: If a string contains a valid numeric value (e.g.,
"10"), PHP implicitly casts it to an integer or float before applying the decrement operation. - Non-numeric Strings: Unlike the increment operator (
++), the decrement operator does not support Perl-style alphanumeric string manipulation. Applying--to a non-numeric string has no effect. As of PHP 8.3, this emits anE_WARNING. - Booleans: Applying the decrement operator to a boolean (
trueorfalse) does not alter its value. As of PHP 8.3, this emits anE_WARNING. - Null: Applying the decrement operator to
nullhas no effect and evaluates tonull. As of PHP 8.3, this emits anE_WARNING, and it will throw aTypeErrorin PHP 9.0. (Note: This contrasts with the++operator, which incrementsnullto1). - Objects/Arrays: Applying the decrement operator to an array or an object that does not overload the operator will result in a fatal
TypeError.
Master PHP with Deep Grasping Methodology!Learn More





