Home  >  Article  >  Backend Development  >  What are the differences between php include and include_once?

What are the differences between php include and include_once?

烟雨青岚
烟雨青岚Original
2020-06-29 13:35:344276browse

The difference between include and include_once is: include will load the specified file and execute the program inside, and repeat the inclusion multiple times; the include_once function will load the specified file and execute the program inside. If the If the file has already been included, it will not be included again.

What are the differences between php include and include_once?

The difference between include and include_once

include will load the specified file and execute the program inside; repeat The reference is included multiple times.

include_once function will load the specified file and execute the program inside; this behavior is similar to the include statement, the only difference is that if the file has already been included, it will not be included again.

include

<?php
include "index.php";
// 其他代码
//
include "index.php";
?>

include_once

<?php
include_once "index.php";
// 其他代码
//
include_once "index.php";
?>

Recommended tutorial: "php tutorial"

The above is the detailed content of What are the differences between php include and include_once?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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