Tutorialsplane

PHP Require Vs Include


PHP Require Vs Include:– When we want to import a file content into another php file then simply we can use include keyword but have you ever think that will will happen if file does not exists which we want to access ; it will execute echo statement excluding the file content.Now we use require keyword to eleminate execution of echo statement which will execute unnecessary strings.


PHP Require Vs Include | Example

In below example we use simplephp2.php file name instead of simplephp.php mistakenly so will can see outputs displaying “Name of Alex ” extra string used in echo statement using include; but this undesired echo statement will not be executed when we use require .

Example of PHP Require Vs Include.

<?Php include ("simplephp2.php");
echo "<br?>";
echo "Age of Alex is ".$age;
?>
<?Php require ("simplephp2.php");
echo "<br?>";
echo "Age of Alex is ".$age;
?>

PHP Tutorial