【发布时间】:2018-10-12 21:10:48
【问题描述】:
我有这样的代码:
function someFunction($myKey){
switch($myKey){
case 'equals':
$condition = '=';
break;
case 'notequals':
$condition = '!=';
break;
default:
$condition = 'like';
break;
}
return $condition;
}
echo someFunction(1); // output 'like' good
echo someFunction('equals'); // output '=' also good
echo someFunction(0); // but here output '=' why ?
echo someFunction(true); // and here also '=' why ?
正如我所评论的,为什么 0 和 true 使用第一种情况而不是默认情况?
虽然我修复了在切换条件之前将$myKey 转换为字符串
但我很好奇我在这里做错了什么。
【问题讨论】:
标签: php variables switch-statement conditional-statements