PHP return to exit break Contiue detailed

Source: Internet
Author: User
Tags foreach exit continue end execution integer php and string
  Return, break, and contiue are language constructs, like if statements, but exit is a function.   1.exit function: Output A and terminate the current script outputs a message and terminates the existing scripts. If a piece of text includes multiple scripts that start with <?php and end with?>, exit exits all scripts. For example, a PHP text including the code, it is not exported to the world. <?php echo "Hello"; Exit?> <?php echo "World";?> syntax format: void means no return value. void exit ([string $status]) void exit (int $status) If status is a string, this function prints the status just BEFO Re exiting. If status is a string, this function prints status before the script exits. The If status is a integer, that value would also be used as the exit status. Exit statuses should being in the range 0 to 254, the exit status 255 are reserved by PHP and shall not being used. The status 0 is used to terminate the successfully. If the status is an integer, the integer is used as an exit state. Exit status should be from 0 to 254, exit State 255 is reserved by PHP and is not allowed. State 0 is used to indicate a successful termination program.     2.return language structure usage   function: terminating function execution and returning a value from function   3.break and continue   used in For,foreach,while,do. While or in the switch structure.   Break End Current For,foreach,while,do ... While or the execution of the switch structure.   BreaK can accept an optional numeric parameter to decide to jump out of several cycles.   Code:   <?php $arr = Array (' One ', ' two ', ' three ', ' four ', ' Stop ', ' five '); while (the list (, $val) = each ($arr)) {if ($val = = ' Stop ') {break; } echo "$val <br>\n";}     $i = 0 ; while (+ + $i) {switch ($i) {case 5:echo ' at 5<br>\n '; break 1;  case 10:echo ' at 10; Quitting<br>\n "; Break 2;  Default:break; }?> Continue is used in the loop structure to skip the remaining code in this loop and begin the next loop of this loop structure.   NOTE: Notice that the switch statement is considered a looping structure for continue purposes in PHP.   Continue accepts an optional numeric parameter to decide to skip several cycles to the end of the loop.   Code:   <?php while ($key, $value) = each ($arr)) {if (!) ( $key% 2)) {//skip odd members continue;} do_something_odd ($value); }   $i = 0; while ($i + + < 5) {echo "outer<br>\n"; while (1) {echo "middle<br>\n"; while (1) {echo inner<br> \ n "; Continue 3; echo "This never gets output.<br>\n"; echo "Neither does this.<br>\n"; }?>

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.