① Functions and usage
This reduces code duplication.
Include (_ once) ("file path") and require (_ once) ("file path ")
② Understanding
To put it bluntly, replace include (_ once) and require (_ once) with the content in the contained file.
③ Note
The include/require file must contain <? Php?> Because when the file is included, we first understand that the content of the file is a normal string, and encounter <? Php?> Label, to explain
④ Path
You can use an absolute path or a relative path. You can use both forward and backward slashes in windows. In linux, you can only recognize forward slashes. Therefore, it is best to use forward slashes.
⑤ Difference
Include indicates the inclusion. If the file cannot be found, the system reports a warning error and the program continues to execute.
Require is required. If the file cannot be found, a fatal error (fatal error) is reported, and the program stops executing.
After the value is added once, the system determines that if the value already exists, it will not include the second time.
Eg: The content of a. php file is <? Php $ a ++;?>
The content in the B. php file is $ a = 5; require_once ("a. php"); echo $ a; require_once ("a. php"); echo $;
The first output is 6, and the second output is 6 .. _ Once is only included once. If once is not added, the second output will be 7
⑥ Trade-off
For example, if the system configuration is missing and the website does not run, require is used. If a statistical program is missing, the website only needs to count fewer people. This is not necessary, you can use include
However, adding or not adding once is the difference in efficiency. In addition, although the system helps you consider loading only once, the system's judgment will reduce the efficiency. Therefore, it should be at the beginning of development, modify the directory structure and try not to use _ once.
7. Special usage
Use include/require to return the returned values of included pages
A. php page:... return $ value; B. php page: $ v = include ("a. php ");
<! -- [Endif] -->
This usage is occasionally encountered during website configuration!