您好,欢迎来到外链网!
当前位置:外链网 » 站长资讯 » 专业问答 » 文章详细 订阅RssFeed

scandir函数PHP scandir函数与示例,subtotal函数用法示例

来源:互联网 浏览:92次 时间:2023-04-08

scandir函数

PHP scandir()函数 (PHP scandir() function)

The full form of scandir is "Scan Directory", the function scandir() is used to get the list of the files and directories available in the specified directory.

scandir的完整格式为“ Scan Directory” , 函数scandir()用于获取指定目录中可用的文件和目录的列表。

Syntax:

句法:

scandir(directory, sorting_order, context);

Parameter(s):

参数:

directory – It specifies the directory name (or path) from there we have to get the list of the files and directories

directory –它指定目录名称(或路径),从那里我们必须获取文件和目录的列表

sorting – It is an optional parameter; its default value is o (alphabetically sorting order). 1 can be used to descending order.

排序 –这是一个可选参数; 其默认值为o(按字母顺序排序)。 1可用于降序。

context – It is an optional parameter; it is used to specify the context (a set of options that can modify the behavior of the stream) to the directory handle.

上下文 –它是一个可选参数; 它用于指定目录句柄的上下文(一组可以修改流行为的选项)。

Return value:

返回值:

It returns an array of the files and directories, returns "False" on function execution failure.

它返回文件和目录的数组,函数执行失败时返回“ False”。

Example: PHP code to get and print the list of files and directories of a given directory

示例:获取和打印给定目录的文件和目录列表PHP代码

<?php//directory name$path = "/home";//assigning the return array in $arr1//defualt in ascending order$arr1 = scandir($path);//assigning the return array in $arr2//Using 1 for descending order$arr2 = scandir($path,1);//printing the resultsprint_r($arr1);print_r($arr2);?>

Output

输出量

Array( [0] => . [1] => .. [2] => folder1 [3] => folder2 [4] => folder3 [5] => main.php)Array( [0] => main.php [1] => folder3 [2] => folder2 [3] => folder1 [4] => .. [5] => .)

翻译自: https://www.includehelp.com/php/scandir-function-with-example.aspx

scandir函数

58520952