Calls an external script to execute.
A script can use include() to call another script. The called script is executed with the current scope of the calling script, almost as if the contents of the called script were in the place of the include() call. The called script can, however, return a status to the calling script using the return statement. If the file specified in the include() call does not exist, a warning results.
The use of include() allows for code modularity and reuse. Functions, classes, data structures, and so on can be placed in a file that can be included in multiple other scripts.
<?php
///////////////////////////
// add.php
// -------
//
// function add($a, $b) {
// return ($a + $b);
// }
//
///////////////////////////
include("add.php");
print "3 + 5 = " . add(3, 5);
?>
3 + 5 = 8
A file with a function definition is included into the script. The function is used to add the numbers three and five.