Combining Multiple Files with Includes3:58 with Alena Holligan
Instead of writing all our code in a single file, PHP allows us to INCLUDE other files, so they function as part of the current page, while keeping them separate. This is very useful for organization and not repeating code for things such as footers and navigation.
How includes work
Included files act as if you had pasted the code directly into the file. Any variables that have already been defined in the main file such as display_name can be utilized and CHANGED. If the file cannot be included PHP will give an error, but continue to process the script. If you want to guarantee that the file is included before continuing on, you should use 'require'.
include - includes and evaluates the specified file.
include_once - the only difference being that if the code from a file has already been included, it will not be included again, and include_once returns TRUE. As the name suggests, the file will be included just once.
require - is identical to include except upon failure it will also produce a fatal error. In other words, it will stop the script whereas include only emits a warning which allows the script to continue.
require_once - identical except PHP will check if the file has already been included, and if so, not include it.
You need to sign up for Treehouse in order to download course files.Sign up