By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

PHP Include vs Include once

What the difference is between Include and Include_once in PHP.

Created: 2012-02-25 17:25

PHP Include VS Include_once what exactly is the difference? Using includes is a useful way to minimize your scripts, and make them easier to maintain. Many beginners are however confused about when to use the different types of includes, this is also something which is covered in the PHP Includes Tutorial here on Brugbart.

The normal Include statement will just include the file again and again, but when include_once is used it will only be included again if it has not already been included. This is useful if you have functions or statements that include files, and that are used multiple times throughout the script.

Below is a small illustration of a basic script that uses include_once instead of include.

include_once "whatever.php"; // Includes whatever.php
include_once "whatever.php"; // Won't do anything, since the file was already included.