scandir函数_PHP scandir()函数与示例

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 results
print_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函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值