Let's talk about the use of the Exit function.
Function: output a message and terminate the current script.
If a paragraph of text contains more than one script that ends, exit exits the current script.
For example, a PHP text including the code, then output to the world.
<%
echo "Hello";
Exit
?>
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 status before the script exits.
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.
Use of the return language structure
Function: Terminate the execution of a function and return a value from a function
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.
A break can accept an optional numeric parameter to decide to jump out of several loops.
Code:
Copy Code code as follows:
$arr = Array (' One ', ' two ', ' three ', ' four ', ' Stop ', ' five ');
while (the list (, $val) = each ($arr)) {
if ($val = = ' Stop ') {
Break
}
echo "$val
\ n ";
}
$i = 0;
while (+ + $i) {
Switch ($i) {
Case 5:
echo "at 5
\ n ";
Break 1;
Case 10:
echo "at 10; Quitting
\ n ";
Break 2;
Default
Break
}
}
?>
Continue the next loop in the loop structure used to skip the remaining code in this loop and begin execution of this loop structure.
Note: Note that the switch statement in PHP is considered a looping structure for continue purposes.
Continue accepts an optional numeric parameter to decide to skip several cycles to the end of the loop.
Code:
Copy Code code as follows:
<code>
<?php
while (the list ($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";
}
?></code>
Note: This article from the Internet, the source is unknown