gpt4 book ai didi

switch语句中的php空值混淆

转载 作者:IT王子 更新时间:2023-10-28 23:52:50 25 4
gpt4 key购买 nike

我有以下 php 代码,它给我带来了意想不到的结果:

$foo = NULL;

switch($foo)
{
case 0:
print "What?!";
}

我希望结果什么都没有,但它与情况 0 匹配。php 手册说 NULL 是一个非值,那么它怎么可能等于 0?

最佳答案

switch 语句适用 loose comparison这意味着以下内容被视为等同于 0:

false
0
"0"
NULL
"any string"
""

关于switch语句中的php空值混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7091671/

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