Home > Article > Backend Development > How to use php exit function
The exit() function is a built-in function in PHP that is used to output messages and terminate the current script. The exit() function only terminates the execution of the script. The syntax is exit(message), and the message to be displayed is passed as a parameter to the exit() function, which terminates the script and displays the message.
How to use the php exit() function?
exit() function outputs a message and exits the current script.
Syntax
exit(message)
Parameters:
message: Required. Specifies the message or status number to be written before exiting the script. Status numbers are not written to the output.
Return value: This function does not return any value.
Note:
1. exit() is a language structure. If no status is passed, it can be called without parentheses.
2. If the status passed as a parameter is an integer, the value will be used as the exit status without printing.
3. The exit status should be in the range of 0 to 254, and the exit status 255 should not be used because it is reserved by PHP.
Let’s take a look at how to use the php exit() function through an example.
Example
<?php header("content-type:text/html;charset=utf-8"); $a=5; $b=5.0; if($a==$b) { exit('变量相等'); } else { exit('变量不相等'); } ?>
Output:
变量相等
The above is the detailed content of How to use php exit function. For more information, please follow other related articles on the PHP Chinese website!