Include other PHP File in PHP Script
Include other PHP File in PHP Script. This is a wonderful function which PHP have which enable us to include files along the way.
What are the Benefits of including PHP File in your PHP Script
- Your Code will look tidy
- Easier to do debugging when an error occur
- You do not need to write repetitive code
- Easier to organise your file.
Normally , Web Developer will programme the Header php and footer PHP file separately and then include into the main index HTML file. This enable the Developer to add in Javascripts , code etc. Doing this enable the developer to debug more easily in compare to stepping into a chunk of code to look what is the problem.
There are a few scripts / Command use to include PHP File
- require(‘yourphpfile.php’) ; – Click here to learn more
- include ‘yourphpfile.php’; – Click here to Learn more.
- require_once(‘yourphpfile.php’); – Click here to Learn more
Check out the Sample Code Below.
<?php require('yourphpfile1.php'); include 'yourphpfile2.php'; require_once('yourphpfile3.php'); ?>
Learn how to use PHP Function Arguments here
Leave a Reply