Terminating script execution refers to telling the PHP engine through a statement that other statements after this statement do not need to be executed.
PHP provides three ways to terminate script execution: return, die, exit
return: Exit at this point. If it is in a function, it means exiting the function. If it is in a script , indicating that the script stops executing
//return //return '*'; //exit //exit; //直接停止,不需要输出任何提示信息 //exit('stop here') ; //带括号表示在此处终止,但是要输出提示信息 //dieexit是一样的//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 '*';
Based on the above possibilities, the PHP configuration file (project configuration file: database connection information, etc.) adopts the above method
<?php //项目配置文件 return array( 'host' =>'localhost', 'port' =>'3306', 'user' =>'root', 'pass' => 'root' );
Related recommendations:
PHP video tutorial: https://www.php.cn/course/list/29/type/2.html
The above is the detailed content of Introduction to how to terminate script execution in PHP. For more information, please follow other related articles on the PHP Chinese website!