寻找更简单的方法来完成:
$switch_success = false;
switch ($var){
case "a":
// do some stuff
$switch_success = true;
break;
case "b":
// do some stuff
$switch_success = true;
break;
case "c":
// do some stuff
$switch_success = true;
break;
}
if ($switch_success){
// switch was successful - run once only if switch finds a matching case
}
可能是另一个 case 关键字,例如default
仅 for any
or all
:
case "c":
// do some stuff
break;
all:
// switch was successful - run once only if switch finds a matching case
或者可能 ...
$switch_success = switch ($var){
case "a":
// do some stuff
break;
case "b":
// do some stuff
break;
case "c":
// do some stuff
break;
}
if ($switch_success) //...
只是尝试了无济于事,但只是想说明我的意图。