Home>Article>Backend Development> Detailed introduction to goto operator in php

Detailed introduction to goto operator in php

黄舟
黄舟 Original
2017-06-25 13:31:22 1792browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn