Home > Backend Development > PHP Tutorial > Summary of issues related to goto in php

Summary of issues related to goto in php

黄舟
Release: 2023-03-11 12:42:01
Original
1986 people have browsed it

What I am doing is a small thing with multiple conditional judgments . In order to have a clear structure and facilitate expansion, I want to use if else. Every time else, I use goto to jump to the next condition. Each piece of code has been tested separately. It's normal. For example, there is always a problem if you directly enclose the words in a with curly brackets. Please give me some advice.

if(){
do something;
}else{
goto a;
}
a:{
$x=1;
$y=2;
计算语句..
}
Copy after login

In the demonstration examples I saw, {} was used. At most, only one sentence was executed. I want to Execute multiple sentences, including assignment and calculation
Isn't it true that curly brackets can only be used for calculation and not assignment?

Hello, gotooperator 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 in the same file and scope. That is to say, you cannot jump out of a function or class method, nor can you jump into another function. You also cannot jump into any loop or switch structures. Common usage is to break out of a loop or switch, which can replace multi-layer break.

Example #1 goto example

<?php
goto a;
echo &#39;Foo&#39;;
 
a:
echo &#39;Bar&#39;;
?>
Copy after login

The above is the detailed content of Summary of issues related to goto 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