(PHP 5 >= 5.3.0, PHP 7)
goto 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷转锟斤拷锟斤拷锟斤拷锟叫碉拷锟斤拷一位锟矫★拷锟斤拷目锟斤拷位锟矫匡拷锟斤拷锟斤拷目锟斤拷锟斤拷锟狡硷拷锟斤拷冒锟斤拷锟斤拷锟斤拷牵锟斤拷锟斤拷锟阶革拷锟斤拷锟� goto 之锟斤拷锟斤拷锟侥匡拷锟轿伙拷玫谋锟角★拷PHP 锟叫碉拷 goto 锟斤拷一锟斤拷锟斤拷锟狡o拷目锟斤拷位锟斤拷只锟斤拷位锟斤拷同一锟斤拷锟侥硷拷锟斤拷锟斤拷锟斤拷锟斤拷也锟斤拷锟斤拷说锟睫凤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟洁方锟斤拷锟斤拷也锟睫凤拷锟斤拷锟诫到锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷也锟睫凤拷锟斤拷锟诫到锟轿猴拷循锟斤拷锟斤拷锟斤拷 switch 锟结构锟叫★拷锟斤拷锟斤拷锟斤拷锟斤拷循锟斤拷锟斤拷锟斤拷 switch锟斤拷通锟斤拷锟斤拷锟矫凤拷锟斤拷锟斤拷 goto 锟斤拷锟斤拷锟斤拷锟� break锟斤拷
Example #1 goto 示锟斤拷
<?php
goto a;
echo 'Foo';
a:
echo 'Bar';
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
Bar
Example #2 goto 锟斤拷锟斤拷循锟斤拷示锟斤拷
<?php
for($i=0,$j=50; $i<100; $i++) {
while($j--) {
if($j==17) goto end;
}
}
echo "i = $i";
end:
echo 'j hit 17';
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
j hit 17
Example #3 锟斤拷锟斤拷写锟斤拷锟斤拷效
<?php
goto loop;
for($i=0,$j=50; $i<100; $i++) {
while($j--) {
loop:
}
}
echo "$i = $i";
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
Fatal error: 'goto' into loop or switch statement is disallowed in script on line 2
Note:
goto 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 PHP 5.3锟斤拷锟斤拷锟较版本锟斤拷效锟斤拷