Introduction and usages of PHP Goto statement

Source: Internet
Author: User
Tags goto

This article mainly introduces what is the PHP goto statement and goto operator usages, need friends can refer to the following

The goto operator can be used to jump to a specified position in a program. The target location can be marked with a colon for the target name. The Goto in PHP has a certain limit and can only jump in the same file and scope, which means you can't jump out of a function or class method, and you can't skip to another function. You also can't jump into any loops or switch structures.   A common use is to jump out of loops or switch, instead of multiple layers of break. The usage is very simple: goto after the flag with the target position, in the target location with a colon marked with the target name, as follows: The code is as follows: <?php goto A;   Echo ' Foo ';//This sentence is skipped over A:echo ' Bar ';   The above example outputs the result: Bar;    For ($i =0, $j =50 $i <100; $i + +) {while ($j-) {if ($j ==17) goto end; } echo "i = $i";   End:echo ' J hit 17 '; The above example outputs the result: The J hit?> note:the goto operator is valid only in PHP 5.3 and above.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.