Home >Backend Development >PHP Problem >How to use php exit function

How to use php exit function

青灯夜游
青灯夜游Original
2019-05-26 17:31:075304browse

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 php exit function

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(&#39;变量相等&#39;); 
 } 
else { 
    exit(&#39;变量不相等&#39;);  
 } 
?>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn