Let’s first talk about the usage of exit function.
Function: Output a message and terminate the current script.
If a piece of text includes multiple scripts ending with , exit will exit the current script.
For example, if a php text includes the following code, the output is 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 status is an integer, this integer will be used as the exit status. Exit status should be from 0 to 254, exit status 255 is reserved by PHP and is prohibited from use. Status 0 is used to indicate successful termination of the procedure.
Usage of return language structure
Role: Terminate the execution of a function and return a value from the function
break and continue are used in for, foreach, while, do..while or switch structures.
break ends the execution of the current for, foreach, while, do..while or switch structure.
break can accept an optional numeric parameter to determine how many loops to break out of.
Code:
Copy code The code is as follows:
$arr = array ('one', 'two', 'three', 'four', 'stop', 'five');
while ( 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;
}
}
?>
Copy code The code is as follows:
while (list ($key, $value) = each ($arr)) {
if (!( $key % 2)) { // skip odd members
continue;
}
do_something_odd ($value);
}
$i = 0;
while ($i++ < 5) {
echo "Outer
n ";
while (1) {
echo " Middle
n";
while (1) {
echo " Inner
n";
continue 3;
}
echo "This never gets output.< br>n";
}
echo "Neither does this.
The above introduces the difference and usage of return and exit, break and contiue in valkyrie destruction PHP, including the content of valkyrie destruction. I hope it will be helpful to friends who are interested in PHP tutorials.