PHP中die()和exit()函数的区别
PHP exit()函数:在PHP中, exit()函数打印一条消息并退出应用程序。它通常用于在发生错误时打印不同的消息。当没有错误并且必须停止执行时使用exit() 。
句法:
exit("Message goes here");
or
exit();
例子:
exit("This request is processed");
方案一:
PHP
PHP
PHP
输出:
This is an exit function in php
方案二:
PHP
输出:
variables are equal
PHP die()函数: 在PHP中, die()与exit()相同。程序的结果将是一个空屏幕。当出现错误并且必须停止执行时使用 die()。
句法:
die("Message goes here");
or
die();
例子:
die('Oops! Something went wrong');
程序:
PHP
输出:
No Output
注意:上述程序的输出将是一个空屏幕,因为它类似于 exit(),die() 只能打印字符串值。
die() 和 exit() 函数的区别: die() exit()The die() method is used to throw an exception The exit() method is only used to exit the process. The die() function is used to print the message. The exit() method exits the script or it may be used to print alternate messages. This method is from die() in Perl. This method is from exit() in C.