Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:目录中的最后一个文件_Php_File - Fatal编程技术网

PHP:目录中的最后一个文件

PHP:目录中的最后一个文件,php,file,Php,File,如何使用php获取目录中最后一个文件的名称(按字母顺序)?谢谢。使用扩展,您只需使用 $all_files = scandir("/my/path",1); $last_files = $all_files[0]; 该命令返回一个数组,其中包含目录中的文件列表。第二个参数指定排序顺序(默认为升序,1表示降序) -只需使用end($array)来收集生成数组中的最后一个值。scandir()没有指定它使用的排序,因此如果文件中包含非ASCII字符,则结果可能不准确。人们可能会认为它与sort

如何使用php获取目录中最后一个文件的名称(按字母顺序)?谢谢。

使用扩展,您只需使用

$all_files = scandir("/my/path",1);
$last_files = $all_files[0];
该命令返回一个数组,其中包含目录中的文件列表。第二个参数指定排序顺序(默认为升序,1表示降序)



-只需使用end($array)来收集生成数组中的最后一个值。

scandir()
没有指定它使用的排序,因此如果文件中包含非ASCII字符,则结果可能不准确。人们可能会认为它与sort sort()相同,使用字符串选项。@Ignacio:,“默认排序顺序为字母升序”@cb160:“字母顺序”是什么意思,当你混合德语、日语和韩语时?嗯,其他答案要简洁得多。
$files = scandir('path/to/dir');
sort($files, SORT_LOCALE_STRING);
array_pop($files);
$files = scandir('path/to/dir');
sort($files, SORT_LOCALE_STRING);
array_pop($files);