What is the difference between include and require functions in PHP?

The main difference between the include and require functions in PHP is how they handle errors. If the file being included is not found, include will only produce a warning and continue executing the script, while require will produce a fatal error and stop the script execution. Therefore, if the file being included is crucial for the script to run, it is better to use require to ensure that the script does not continue if the file is missing.

// Using require to include a file that is essential for the script to run
require 'essential_file.php';

// Using include to include a file that is not essential for the script to run
include 'optional_file.php';