The include function takes a file name and inserts that file’s contents into the script that calls the include function. You can type up a common header, footer or menu file that you want all your web pages to include. When you add a new page to your site, instead of having to update the links on several web pages, you can simply change the Menu file. Similarly if you want to change or add a link in footer or you want to change image in header of website, you do not need to go to every page to do that and you just open up files footer and header and change these which will effect on all the website. It saves a lot of time.
Usage is given below.
<?php include("header.php"); ?>
Consider this image. Suppose this is index.php. I have included header, menu and footer in index.php at proper places where these must be and for next page I will repeat the process and just include header, footer and menu by above code example, doesn’t matter how many pages are in number.
The include command takes all the text that exists in the specified file and copies it into the file that uses the include function. Include is quite useful when you want to include the same PHP, HTML, or text segment on multiple pages of a website. The include function is used widely by PHP web developers.