我从ftp服务器以数组形式返回了文件:
Array
(
[0] => FOLDER./Images.Vacation.2018
[1] => ./Images.Vacation.2018/Racoon001.jpg
[2] => ./Images.Vacation.2018/Racoon002.txt
[3] => ./Images.Vacation.2018/the.racoon.swimming.mp4
[4] => ./Images.Vacation.2018/the.racoon.swimming.slv
[5] => FOLDER./WestImages
[6] => ./WestImages/Ramco.txt
[7] => ./WestImages/Ramco.jpg
[8] => FOLDER./WestImages/Subimages
[9] => ./WestImages/Subimages/Image001.jpg
[10] => ./WestImages/Subimages/Image002.jpg
[11] => ./WestImages/West.Ramco.Swimming.mp4
)如您所见,SubImages在WestImages之前返回,这是wrong...so,我无法使用和
sort($contents);但是它返回错误的sorting...how来重写函数以返回正确的排序,就像上面给出的那样?
谢谢。发布于 2019-06-08 11:12:04
这不是一个很好的解决方案,但是您可以使用preg_grep获取文件夹名,然后循环它们并对文件进行grep。
$folders = preg_grep("/^FOLDER.*/", $arr);
foreach($folders as $folder){
$result[] = $folder;
$result = array_merge($result, preg_grep("/^\." . str_replace(["FOLDER.", "/"], ["","\/"], $folder) . "\/[A-Za-z0-9\.]+$/", $arr));
}
var_dump($result);https://stackoverflow.com/questions/56505364
复制相似问题