PHP get_included_files() Function
Last Updated :
09 Mar, 2023
The get_included_files() is an inbuilt function that returns an array with names of included or required files.
Syntax:
get_included_files(): array
Parameters: This function does not accept any parameters.
Return Values: It returns an array of the names of files.
Example 1: This example demonstrates the get_included_files() function.
PHP
<?php
include 'print.php' ;
$nameFile = get_included_files() ;
var_dump( $nameFile ) ;
?>
|
Note: The included file has to be present in the correct directory. In this example, it’s ‘print.php’.
Output:
array(2) {
[0] => string(51) “/home/dachman/Desktop/Articles/GFG/Method/index.php”
[1] => string(51) “/home/dachman/Desktop/Articles/GFG/Method/print.php”
}
Example 2: The following code also demonstrates the get_included_files() function.
Note: The output this these programs must be different according to your system path or where you store your files.
PHP
<?php
include 'print.php' ;
$nameFile = get_included_files() ;
foreach ( $nameFile as $filename ){
echo $filename . "\n" ;
}
?>
|
Output:
/home/dachman/Desktop/Articles/GFG/Method/index.php
/home/dachman/Desktop/Articles/GFG/Method/print.php
Reference: https://www.php.net/manual/en/function.get-included-files.php
Share your thoughts in the comments
Please Login to comment...