Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP decrement NULL value issue

I have noticed if a value is null i can increment it by one using ++$value but its not true about decrement , meaning --$value would return null , why?

$value = null;
echo ++$value; // 1
echo --$value; // null (I'm expecting -1)
like image 628
alex Avatar asked Jul 22 '26 02:07

alex


1 Answers

Ref# language.operators.increment.php

Note: The increment/decrement operators only affect numbers and strings. Arrays, objects and resources are not affected. Decrementing NULL values has no effect too, but incrementing them results in 1.

like image 112
Murad Hasan Avatar answered Jul 23 '26 15:07

Murad Hasan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!