Introduction to how to terminate script execution in PHP

Release: 2023-04-08 13:06:02
forward
2409 people have browsed it

Introduction to how to terminate script execution in PHP

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') ;
Copy after login

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 &#39; demo13_ stop.php&#39; ;

var_ dump($test) ;
Copy after login

demo13_stop.php

<?php
   //终止脚本执行
   echo &#39;start&#39;;

   //return
   return &#39;*&#39;;
Copy after login

Based on the above possibilities, the PHP configuration file (project configuration file: database connection information, etc.) adopts the above method

<?php
	//项目配置文件
	return array(
	       &#39;host&#39; =>&#39;localhost&#39;,
	       &#39;port&#39; =>&#39;3306&#39;,
	       &#39;user&#39; =>&#39;root&#39;,
	       &#39;pass&#39; => &#39;root&#39;
	);
Copy after login

Related recommendations:

PHP video tutorial: //m.sbmmt.com/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!

Related labels:
php
source:csdn.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!