Home > Backend Development > PHP Tutorial > Detailed introduction to goto operator in php

Detailed introduction to goto operator in php

黄舟
Release: 2023-03-11 12:44:02
Original
1940 people have browsed it

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 a function and a method of a class

Cannot "jump" into another function

Cannot "jump" into any loop or switch structure

You can "jump out" of a loop or switch. The general usage is to replace multi-layer break

Simple practical case

goto  target;
echo  'Hi world' ;
target :
echo  'hello world' ;
Copy after login

Result

hello world
Copy after login
$i = 0;
$j = 50 ; 
for( $i < 100 ;  $i ++) {
while( $j --) {
if( $j == 17 ) 
goto  end ; 
}  
}
echo  "i =  $i " ;
end :
echo  &#39;j hit 17&#39; ;
Copy after login

Result

j hit 17
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template