Php goto function syntax

Source: Internet
Author: User
Tags goto

PHP's GOTO syntax redirects to a specified position, as shown in the code, goto display defines a display after the code, so that when the goto display statement is executed, it will jump to the place where the display is defined to start execution. This is the added syntax of PHP5.3 and supports PHP7.


Public function index ()
{
If (! I ('Get. Search ')){
Goto display;
    }
 
// 800 words are omitted here
 
$ This-> assign ('account', self: $ account );
$ This-> assign ('pay _ type', I ('Get. pay_type '));
$ This-> assign ('list', $ list );
 
Display:
$ This-> display ();
}


The usage is simple: the goto is followed by the target position mark, and the target name is marked with a colon on the target location, as shown below:
 
The code is as follows: <? Php
Goto;
Echo 'foo'; // This sentence is skipped
 
A:
Echo 'bar ';
 
// The output result of the preceding example is 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 output result of the preceding example is j hit 17.
?>
 
 
 
Note:
The goto operator is only valid in PHP 5.3 and later versions.

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.