When we start a new project, we collect lots of files and make some small function to star the site, for a long run of site we use the different file locations like below
Header.php for site header
Left.php for left side of the site
Footer.php for footer site panel
These three panel is most commonly used in web development, the question is why we use this, because we normally use the comment content on this area and it’s very simple to change any time.
Any time you can change the one file and view the effect of file on full project.
we can use the file like below
include('header.php'); include('left.php'); include('footer.php');
PHP include file is also use the define variable which is used in full project as well, like below example
in variable.php
<?php $x=3 ?>
now you can add the include file in mail file and get the x value in this
<?php echo " Try to get the value of x before include the file".$x; Include("variable.php"); echo "Try to get the value of x after include the file ".$x; ?>
Output as below
Try to get the value of x before include the file Try to get the value of x after include the file 3
As we seen in above example, we get the value in variable $x after include the file.
Require() and require_once() is also a good option to include in project.
If you need some variable to show content on page then you must add the require file option, because if you include the file and forget to add some variable or some database related issue then you get lot’s of error, to avoid this you must use the require() function.
Require function is used as include
<?php require("filename.php"); require_once("filemane.php") ?>
require_once and include_once used when you use some complex include file like using some filter to include or not to include the file.
This function check the file, if this file already include then PHP did not include it again.