php methods to stop script running are: return, die, exit. If exit is used in a function, it means exiting the function. If it is used in a script, it means the script stops execution. Return is used in functions to return to the place where the function is called, and in scripts to return to the place where the script is included.
Terminating script execution refers to telling the PHP engine through a statement that other statements after this statement do not need to be executed.
(Recommended tutorial: php tutorial)
PHP provides three ways to terminate script execution: return, die, exit.
Let’s introduce them separately:
exit: exit when executed. If it is in a function, it means exiting the function. If it is in a script, it means the script stops executing.
//exit; //直接停止,不需要输出任何提示信息 //exit('stop here') ; //带括号表示在此处终止,但是要输出提示信息 //die和exit是一样的//die; die('stop here') ;
return: The return of the function is to return to the place where the function is called, and the return of the script is to return to the place where the script is included.
<?php //包含demo13_ stop. php $test = include ' demo13_ stop.php' ; var_ dump($test) ; demo13_stop.php <?php //终止脚本执行 echo 'start'; //return return '*';
Code implementation:
Project configuration file: database connection information, etc.
<?php //项目配置文件 return array( 'host' =>'localhost', 'port' =>'3306', 'user' =>'root', 'pass' => 'root' );
The above is the detailed content of How to stop script running in php. For more information, please follow other related articles on the PHP Chinese website!