| |
|
PHP file Include Once script and example |
If we want to include a file once only and further calling
of the file will be ignored then we have to use the PHP function include_once().
This will prevent problems with function redefinitions, variable value
reassignments, etc. Here is one example to explain this. Before that please
read the php include function to know the php include command.
Let us create one PHP file and name it as data.php . Here
is the content of this file
<?
echo "Hello <br>"; // this
will print Hello with one line break
?>
Now let us create one more
file and from that we will be including the above data.php file . The name of
the file will be inc.php and the code is given below.
<?
include "data.php";
// this will display Hello once
include "data.php";
// this will display Hello once
include "data.php";
// this will display Hello once
include_once
"data.php"; // this will not display as the file is already included.
include_once "data.php"; // this will also not display as the file is already included.
?>
So here in the above code the echo command displaying Hello
will be displayed three times and not five times. The include_once() command
will not include the data.php file again.
| |
| Subscribe |
|
Submit your email address and receive
article and product notifications. Your email is safe with us.
|
|
|
|
|
|