gpt4 book ai didi

php - 为什么在这个数组中 NULL 的递减不是负数?

转载 作者:IT王子 更新时间:2023-10-29 01:12:19 26 4
gpt4 key购买 nike

我试过这个代码

$a = array_fill(0, 4, NULL);
$a[0]++;
++$a[1];
$a[2]--;
--$a[3];
var_dump($a);

结果:

array(4) {
[0]=> int(1)
[1]=> int(1)
[2]=> NULL
[3]=> NULL
}

为什么 2 和 3 索引的值不是负数?

最佳答案

很奇怪,但是 documented在递增/递减运算符 php 文档页面上:

Note: The increment/decrement operators do not affect boolean values. Decrementing NULL values has no effect too, but incrementing them results in 1.

关于php - 为什么在这个数组中 NULL 的递减不是负数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17592559/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com