The goto operator is a new function after PHP5.3+, which is used to jump to another location in the program; its usage is very simple: put the mark of the target location after goto, and mark the target location with the target name plus a colon. , as follows:
But the target location of goto can only be the same file and scope [it cannot jump to a function or class method]. Of course, it can jump out of the loop, but it cannot jump into the loop:
The goto operator can be used to jump to a specified location in the program. The target location can be marked with the target name followed by a colon. Goto in PHP has certain restrictions and can only jump within the same file and scope. This means that you cannot jump out of a function or class method, nor can you jump into another function. You also cannot jump into any loops or switch structures. Common usage is to break out of a loop or switch, which can replace multiple levels of break.
The above routine will output: Bar
goto jump out of loop example
The above routine will output: j hit 17
The following writing is invalid
The above routine will output:
Fatal error: 'goto' into loop or switch statement is disallowed in
script on line 2