php - PHP递减NULL值问题

标签 php null increment decrement

我已经注意到,如果值是null,我可以使用++$value将其值加1,但有关减量则不正确,这意味着--$value将返回null,为什么?

$value = null;
echo ++$value; // 1
echo --$value; // null (I'm expecting -1)

最佳答案

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.

关于php - PHP递减NULL值问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36280786/

相关文章:

php - 使用 SQL 计算记录并在 PHP 中返回

php - 在条件中编写具有可为空值的准备好的语句

mysql - 在 mysql 语句中返回 null 或空字符串

java - 在Java中循环内递增int

redis - 检查并增加 Redis 中的计数器

php - 来自 MySQL JSON 编码数组的 Google 图表

javascript - 检查空跨浏览器的完整方法是什么

c++ - 在数组中使用 NULL 作为终止符?

javascript - 如何在 HTML 中增加一个值?

php - 构造函数依赖注入(inject)如何在 Laravel 中工作?