PHP 递减 NULL 值问题
PHP decrement NULL value issue
我注意到如果一个值是 null
我可以使用 ++$value
将它递增 1 但它不是关于递减的,这意味着 --$value
会 return null
,为什么?
$value = null;
echo ++$value; // 1
echo --$value; // null (I'm expecting -1)
参考号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.
从逻辑上思考一下
你不能从无中拿走一些东西,但你可以在无中添加一些东西。 null不是0,简直就是没有值。
我注意到如果一个值是 null
我可以使用 ++$value
将它递增 1 但它不是关于递减的,这意味着 --$value
会 return null
,为什么?
$value = null;
echo ++$value; // 1
echo --$value; // null (I'm expecting -1)
参考号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.
从逻辑上思考一下
你不能从无中拿走一些东西,但你可以在无中添加一些东西。 null不是0,简直就是没有值。