Isa*_*sca 2 php switch-statement
我正在尝试这样的代码:
$event = 0;
switch ($event) {
case 'content':
echo "/content";
break;
case 'start':
echo "/start";
break;
default :
echo "not available";
break;
}
Run Code Online (Sandbox Code Playgroud)
此代码/content在执行时打印,因此... 0(零,整数,分配给$ event变量)被评估为'content'.为什么?
这就是实际发生的事情
0 == 'content'
Run Code Online (Sandbox Code Playgroud)
Php尝试将字符串content转换为整数.由于content不等于int,因此它默认为0.
导致:
0 == 0
Run Code Online (Sandbox Code Playgroud)