Home >Backend Development >PHP Problem >Detailed explanation of php require usage
php require is a built-in function of PHP, which is used to introduce or include external PHP files. The working principle is that when the own PHP file is executed, the contents of the external file will be included in the own PHP file; When an error occurs in the included external file, the system will throw an error prompt and stop the execution of the php file.
php require usage details
require() is a built-in function of php, which is used to introduce or include external php document.
Working principle: When the own PHP file is executed, the contents of the external file will be included in the own PHP file; when an error occurs in the included external file, the system will throw an error prompt, and Stop the execution of the php file.
Note: When using require, if there is an error in a file, the program will interrupt execution and display a fatal error.
For example, there are two files: cl.php and ts.php. If ts.php needs to use the functions in the cl.php file, it needs to be introduced or included in ts.php. The example is as follows:
cl.php
<?php function show(){ echo "cl.php文件中的show方法被调用了!"; } ?>
ts.php
<?php require 'cl.php'; show(); ?>
Running result:
For more related knowledge, please Visit PHP Chinese website!
The above is the detailed content of Detailed explanation of php require usage. For more information, please follow other related articles on the PHP Chinese website!