使用include和required once()有什么区别? [重复]

This question already has an answer here:

What is the difference between include and required_once()? I want to include another php file let us consider as sample2.php in example1.php.Which is the best practice to use.

</div>

To put it in the simplest terms, your PHP page can still run with an include file not being retrieved, where as if it's a required_once and the file it's trying to get doesn't exist or is not in the right directory, the whole page will fail to load

There are more of these:

  • require_once
  • require
  • include
  • include_once

The once ones will only include the file once in the page if multiple times it is called, whereas the functions without once will call them as many times as they are in your code.