【发布时间】:2021-08-22 06:37:54
【问题描述】:
echo $state; //debug
switch($state){
case "Sleeping":
$label = "Is Sleeping";
case "Running":
$label = "Is Running";
default:
$label = "Could not retrieve state";
}
$state 是从 SQL 数据库(Enum 类型)填充的,echo 消息打印“Sleeping”,但 $label 填充的是默认值
【问题讨论】:
-
您需要在每种情况下都包含断句。执行从第一种情况“下降”到默认情况。 php.net/manual/en/control-structures.switch.php您已经在链接中详细解释了您的代码中发生的事情。
-
对,菜鸟的错误。我通常知道这一点.. :o
标签: php enums switch-statement