get_included_files

(PHP 4, PHP 5, PHP 7, PHP 8)

get_included_files返回被 include 和 require 文件名的 array

说明

get_included_files(): array

返回所有被 includeinclude_oncerequirerequire_once 的文件名。

参数

此函数没有参数。

返回值

返回所有文件名称的 array。

脚本最初被称为”被包含的文件“,所以脚本自身也会和 include 系列函数引用的脚本列在一起。

被多次 include 和 require 的文件在返回的 array 里只会列出一次。

范例

示例 #1 get_included_files() 范例

<?php
// 本文件是 abc.php

include 'test1.php';
include_once
'test2.php';
require
'test3.php';
require_once
'test4.php';

$included_files = get_included_files();

foreach (
$included_files as $filename) {
echo
"$filename\n";
}

?>

以上例程会输出:

/path/to/abc.php
/path/to/test1.php
/path/to/test2.php
/path/to/test3.php
/path/to/test4.php

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top