The include statement in PHP is also used to include any external file in the program. But if we use include statement then it will generate just a warning and execute the program and will display the results as per the input value.
The include statement in PHP
You can understand the include statement using the following example:
$color = 'yellow';
$fruit = 'banana';
echo "A $color $fruit"; // A
echo "A $color $fruit"; // A yellow banana
Difference between include and require statement in PHP
The function of both the statements are almost similar except in case of require statement, if file doesn’t exists then it will generate a fatal error and it will stop the program execution immediately but in case of require statement, it will just check the file and if it doesn’t exists then it will just display a warning and execute the program.
So if we want to be a file is included in the program then we should use the require statement only.
Now I hope you are all clear about the include and require statements.
In next chapter, we will see how to use require_once and include_once.