Difference between include() and require() functions?
This Both function help to include the content of other PHP files into another PHP file.Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.
While using the include() function it adds the content of the page or file into the file where this function is used.If there is any problem in loading a file then the include() function generates a warning but the script will continue execution.
Let us take an Example of include() function, here I’m creating a header.php file which contains the menu.
Now Create a index.php file to add the content.
After including the Page into index.php will like this Image.
Using require() function takes all the text in a specified file and copies it into the file that uses the include function. If there is any problem in loading a file then the require() function generates a fatal error and halt the execution of the script.
Now take a example without using a file we are going to use require() function.
This will Happen when require() function will be used if file will not available at the source.
Use require when the file is required by the application.
Use include when the file is not required and application should continue when the file is not found.