1宝与、switch會(huì)一直運(yùn)行代碼直到找到中斷础锐,所以很容易采用fallthrough的概念并為多個(gè)case運(yùn)行相同的代碼
switch($type) {
case 3:
case 4:
echo "This is not the number you're looking for.\n";
$foo = 92;
break;
case 5:
echo "A copy of Ringworld is on its way to you!\n";
$foo = 34;
break;
}
2牍蜂、在case中添加條件篩選
switch($type)
{
case ($type > 30):
$error = "The value provided is too long.";
$valid = false;
break;
case (!preg_match('/^[A-Z0-9]+$/i', $type)):
$error = "The value must be alphanumeric.";
$valid = false;
break;
default:
$valid = true;
break;
}