PHP » Control Structures » include_once()

Syntax:
mixed include_once(string filepath)
filepath
The path to the file that is to be called.

Calls an external script to execute, if it has not already been called.

include_once() is very similar to include(), but is used when there is a risk that including a file more than once will lead to conflicts. This function guarantees that a file is not included more than once during the same execution of a script.

Examples

Code:
<?php
/////////////////////////////
// helloworld.php
// --------------
//
// print "Hello World<br>";
//
/////////////////////////////

for ($i = 0; $i < 10; $i++) {
   include_once("helloworld.php");
}

?>
Output:
Hello World
Explanation:

Even though helloworld.php is included multiple times in a loop, it is only executed once.

See Also: