PHP » Control Structures » include()

mixed include(string filepath)
The path to the file that is to be called.

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.


//  add.php
//  -------
// function add($a, $b) {
//     return ($a + $b);
// }


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.

See Also: