Home>Article>Backend Development> Detailed introduction to goto operator in php
php gotoOperator
can be used to jump to another location in the program. The position can be marked with the target name plus a colon, and the jump instruction is followed by goto followed by the target position mark
Some restrictions on the use of the goto operator
The target position can only Located in the same file and scope
Cannot "jump out" of afunctionand a method of a class
Cannot "jump" into another function
Cannot "jump" into anylooporswitchstructure
You can "jump out" of a loop or switch. The general usage is to replace multi-layerbreak
Simple practical case
goto target; echo 'Hi world' ; target : echo 'hello world' ;
Result
hello world
$i = 0; $j = 50 ; for( $i < 100 ; $i ++) { while( $j --) { if( $j == 17 ) goto end ; } } echo "i = $i " ; end : echo 'j hit 17' ;
Result
j hit 17
The above is the detailed content of Detailed introduction to goto operator in php. For more information, please follow other related articles on the PHP Chinese website!