How to Use include() function in PHP?

include() function

External PHP file is used in any PHP file from include() function.

In the include function, the path of the external PHP file has to be written along with the name of that file. The path is written in double(“”) or single quotes(”).

Syntax for include()

include("path_or_filename"); or
include('path_or_filename');

external_file.php

Source Code :
<?php
echo "external file name is external_file.php";
?>

Example for include() function

current_file.php

Source Code :
<?php
echo "current file name is current_file.php";
include ("external_file.php");
?>
Output :
current file name is current_file.php
external file name is external_file.php

Note: When an external php file is included on another php file through the include() function. If the path of the included file is wrong, then it does not prevent the code of the rest of the file from being executed. It gives a warning message that the file you have given is not there.