Difference Between include and require function in php?

Both include and require function in php perform similar work. Both functions will include and evaluates the specific file while executing the code.

require(): If the file is not found by require(), it will cause a fatal error and halt the execution of the script. include(): If the file is not found by include(), a warning will be issued, but execution will continue.

Assume we have a file called “cars.php”, with some variables defined:

This will produce the following result –

If we do the same example using the require statement, the echo statement will not be executed because the script execution dies after the require statement returned a fatal error:

This will produce the following result –

Thanks for reading my article about “Difference Between include and require function in php?”. If you like this article do me favor by sharing it with your friends.

Digital Technology Hub