Include another php file – include()

If you have worked with C programming, you may have used the preprocessor “#include”. #include is used to include another file in your program. In simpler words, you can split a large program into multiple files and can make use of all the files as a single file with the help of #include directive. Splitting a program helps to logically divide various functionalities into various files.

Similar to #include in C/C++, there is include in PHP. It’s syntax is

include 'filename';

You can also access remote PHP files using include.

Let’s take a simple example. The first file of our consideration is HelloWorld.php


function helloWorld() {

echo "Hello World!";



Now let’s access the above file using include in our second file test.php


include 'HelloWorld.php';




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s