Difference between include() and require() functions In PHP



In my previous post I have described regarding the PHP file inclusion methods these are the include() Function, include_once() Function, require() Function and require_once() Function. In this post I am trying to describe the differences between the include() and require() functions, the includes and the require functions both are used to include the content of a PHP file into another PHP file before it is executed by the server, the main differences are given below:

1. The file included by the include(), generates a warning and the script executes continuously when there is any problem with the included PHP file, where as . The file included by the require(), generates a error and stops the script execution when there is any problem with the included PHP file.

2. The syntax are given below:

<?php

	foreach($values as $pr_data)
	{
	    include 'products.php';// This will includes this file only once
	}

?>

<?php

	foreach($values as $pr_data)
	{
	    require 'products.php';// This will includes this file only once
	}

?>

Want to read more regarding the File Inclusion In PHP?.

This is main diffrences between the include() and require() functions. Thanks and Enjoy the reading.