1, require is loaded before the program interpretation is executed, the content that is loaded is used frequently during the execution of the program interpretation, and the include is used in the interpretation of the execution of certain content to use, include load; If each execution code reads a different file or has a loop that iterates through a set of files, the include is used.
2,include the introduction of file failure, warning, the program continues to execute, require introduced file error, errors, stop execution.
3,include_once and require_once are similar to include and require, but the files they introduce can only be referenced once.
4,include is similar to file_get_contents, but the include return string can be executed, file_get_contents the string will not be executed.
Instance
(1) include conditional reference; require is an unconditional reference.
if ($some) {include ' somefile.php ';}
As above code. If the variable $somg is true, the file somefile.php will be included.
if ($something) {require ' somefile.php ';}
As in the code, but no matter what value $some takes, the following code will include the file somefile.php into the file.
(2) When referencing different files during the iteration
$i = 1;while ($i < 3) {require "Somefile". $i. ". PHP "; $i + +;}
Can be seen from the above code, each time the loop, The program will include the same file somefile1.php, it is clear that this is not what we want, we can see that this code wants to be in each loop, the different files are included, if you want to complete this function, you can only use the include.
$i = 1;while ($i < 3) {include "somefile. $i. php"; $i + +;}
The difference between include and require