我经常使用并看到只有"break"的例子。这是什么意思:
<?php
while ($flavor = "chocolate") {
switch ($flavor) {
case "strawberry";
echo "Strawberry is stock!";
break 2; // Exits the switch and the while
case "vanilla";
echo "Vanilla is in stock!";
break 2; // Exits the switch and the while
case "chocolate";
echo "Chocolate is in stock!";
break 2; // Exits the switch and the while
default;
echo "Sorry $flavor is not in stock";
break 2; // Exits the switch and the while
}
}
?>
'break'语句还有其他可用选项吗?
while
循环内。鉴于条件,它将永远输出“巧克力有库存!” :) - Jason McCreary