sangkrit

What is Include Once Statement


Including many PHP scripts may cause a problem. As include statement does not check for the scripts that are already included. Example:

<?php

include (‘add.php’);

include (‘add.php’);

echo add (2, 2);

?>

Here you will get the error: Cannot redeclare add()

Hence here you should use an include_once statement.

Now by using include_once statement:

<?php

include_once (‘add.php’);

include_once (‘add.php’);

echo (2,2);

?>

This will give the output 4, after execution.


Leave a Reply