PHP is a well known name in the field of website development. It is free and hence widely used by the web developers. PHP is the combination of several functions. There is one function in PHP that every web developer must know that is the include function. Whether you are a newbie or experienced in PHP, it is essential and vital to know for anyone who needs to develop a website. Knowing this function will create your web development much easier and faster.
The PHP include function is very beneficial because it comprises the contents of another file which placed in another location. You may not understand this at first, but this permits you to have a file that is just the header, the footer, or the navigation of your web page. This way, whenever you require modifying it, instead of updating each file, you just modify the one file.
Include is very simple to use in a web page. It needs one argument which is a string of the location of the file to comprise. To apply this function in your web page, see below the format:
$header_file = "header.php";
include($header_file); // Includes the contents of the header file.
include("navigation.php"); // Includes the contents of the navigation file.
These examples show the uses of the include function. In the first example, you can see that how include function use with a variable. In the second example, see the function use with just mention the file name in. Using this function, developers will save a lot of time to maintaining and updating the website.
<?php include 'header.php'; ?> <?php include 'footer.php'; ?>