我有幾個圈,並希望當我用休息來指定一個特定的循環或繼續進行指示繼續進行或中斷特定環路
在PHP doc,它是寫,我可以使用數字數字參數來它有多少嵌套的封閉結構將被分解出來。
$i = 0;
while (++$i) {
switch ($i) {
case 5:
echo "At 5<br />\n";
break 1; /* Exit only the switch. */
case 10:
echo "At 10; quitting<br />\n";
break 2; /* Exit the switch and the while. */
default:
break;
}
}
,但我想一些更友好的是這樣的:
$i = 0;
loop1: // Label/tag of loop1
while (++$i) {
loop2: // Label/tag of loop2
switch ($i) {
case 5:
echo "At 5<br />\n";
break loop2; /* Exit only the switch. */
case 10:
echo "At 10; quitting<br />\n";
break loop1; /* Exit the switch and the while. */
default:
break;
}
}
這可能嗎?
我會建議,而不是中斷使用goto語句來跳轉你的代碼向上或向下,這將是更容易。 –
不要使用'goto'! [這是爲什麼!](https://stackoverflow.com/questions/1900017/is-goto-in-php-evil) –
你可以使用不推薦轉到[http://php.net/manual/fr/control -structures.goto.php](PHP 5> = 5.3.0,PHP 7),在while循環結束時使用標籤(loopend :)。 – okante