PHP include file - Include file more than once


Home - Tutorials - Basics

In this tutorial I will show you how to divide your code into more files and how to include various files into your actual PHP code.

Tutorial info:


Name:PHP include file
Total steps:5
Category:Basics
Level:Beginner

Bookmark PHP include file



Step 3 - Include file more than once


PHP include file


Sometimes it can happen that you want to include a file in your script more than once. There is no problem with it. You can do this by calling include more times. Altough in such case maybe a well organized loop can be better.

So to demonstarte more include calls I have created the following example code:

Code: internal.php
  1. <?php
  2. echo "-->internal.php<--<br/>";
  3. ?>

And the main file is:
Code:
  1. <?php
  2. include ('internal.php');
  3. echo "Multiple include test.<br/>";
  4. include ('internal.php');
  5. echo "Now include it again.<br/>";
  6. include ('internal.php');
  7. echo "And again.<br/>";
  8. include ('internal.php');
  9. ?>
This code will result the following output:
Output:
-->internal.php<-- Multiple include test. -->internal.php<-- Now include it again. -->internal.php<-- And again. -->internal.php<--  





Previous Step of PHP include fileNext Step of PHP include file


Tags: php incluude file, php include, include file, file include, php, include, file


Follow phpf1 on Twitter




F1 Site Family
AJAX F1
HTML F1
Java F1
JavaScript F1
PHP F1

Total time: 0.1448