當您關閉PHP標籤,你不要關閉會話,並且包含的代碼將保留在您選擇打開或關閉的所有php標籤中。
例
- index.php
- includes once connect.php
- includes once foo.php
- includes bar.php
- foo.php
- Contains scope from connect.php
- bar.php
- Contains scope from connect.php
- Contains scope from foo.php
包括和include_once是如果你包括相同的文件多次,它仍然只包含一次的唯一diffrence。
例子包括
<?php
include ('connect.php'); // Includes an evaluates code.
include ('connect.php'); // Includes an evaluates code.
include ('connect.php'); // Includes an evaluates code.
?>
例Include_once
<?php
include_once ('connect.php'); // Includes an evaluates code.
include_once ('connect.php'); // Does nothing.
include_once ('connect.php'); // Does nothing.
?>
如果應用程序使用的模塊,其然後包括:庫這是有用的。爲了確保它不會多次包含相同的庫,只需要一次,就可以使用include_once。
來源
2012-09-10 12:24:31
Kao
不,它足以將其包含在php文件的頂部 – Wearybands