The
goto operator can be used to jump to a specified position in a program. The target location can be marked with a colon for the target name.
The goto operator is added after php5.3+ to jump to another location in the program; the usage is simple: goto followed by a flag with the target location, with a colon marked at the target, as follows: Copy code: Goto A; Echo ' the Script house '; A: echo ' http://www.jb51.net '; But Goto's target location can only be the same file and scope "can not jump to a function and class method", of course, it can jump out of the loop, but can not jump into the loop: Copy code code as follows: <?php for ($i = 0; $i < 3; $i + +) { echo $i. ' <br> '; if ($i = = 1) goto end; End: Echo ' directly ended '; The goto operator can be used to jump to a specified position in a program. The target location can be marked with a colon for the target name. The Goto in PHP has a certain limit and can only jump in the same file and scope, which means you can't jump out of a function or class method, and you can't skip to another function. You also can't jump into any loops or switch structures. A common use is to jump out of loops or switch, instead of multiple layers of break. Code as follows: <?php goto A; Echo ' Foo '; A:echo ' bar ';?> The above routines will output: Bar goto Jump Loop Sample code is as follows: <?php for ($i =0, $j =50; $i <100; $i + +) { while ($j-) { if ($j ==17) goto end; } } echo "i = $i"; End:echo ' J hit ';?> The above routines will output: J hit The following writing is invalid code as follows: <?php Goto Loop; For ($i =0, $j =50 $i <100; $i + +) { while ($j--) { loop: }} echo "$i = $i";?> above routines output: fatal Error : ' Goto ' into loop or switch statement are disallowed in script on line 2