如何在php中对文件列表进行排序

时间:2015-02-01 12:46:39

标签: php sorting

我使用了glob函数来读取目录

        foreach (glob("$path/*.jpg") as $file) {
            array_push($row['images'], $files);
        }

我从上述方法得到的输出如下所示

    [
        "..\/images\/items\/item-16\/img-0.jpg",
        "..\/images\/items\/item-16\/img-1.jpg",
        "..\/images\/items\/item-16\/img-10.jpg",
        "..\/images\/items\/item-16\/img-11.jpg",
        "..\/images\/items\/item-16\/img-12.jpg",
        "..\/images\/items\/item-16\/img-13.jpg",
        "..\/images\/items\/item-16\/img-14.jpg",
        "..\/images\/items\/item-16\/img-15.jpg",
        "..\/images\/items\/item-16\/img-16.jpg",
        "..\/images\/items\/item-16\/img-2.jpg",
        "..\/images\/items\/item-16\/img-3.jpg",
        "..\/images\/items\/item-16\/img-4.jpg",
        "..\/images\/items\/item-16\/img-5.jpg",
        "..\/images\/items\/item-16\/img-6.jpg",
        "..\/images\/items\/item-16\/img-7.jpg",
        "..\/images\/items\/item-16\/img-8.jpg",
        "..\/images\/items\/item-16\/img-9.jpg"
    ]

我想按照这样的顺序排序。

    [
        "..\/images\/items\/item-16\/img-0.jpg",
        "..\/images\/items\/item-16\/img-1.jpg",
        "..\/images\/items\/item-16\/img-2.jpg",
        "..\/images\/items\/item-16\/img-3.jpg",
        "..\/images\/items\/item-16\/img-4.jpg",
        "..\/images\/items\/item-16\/img-5.jpg",
        "..\/images\/items\/item-16\/img-6.jpg",
        "..\/images\/items\/item-16\/img-7.jpg",
        "..\/images\/items\/item-16\/img-8.jpg",
        "..\/images\/items\/item-16\/img-9.jpg",
        "..\/images\/items\/item-16\/img-10.jpg",
        "..\/images\/items\/item-16\/img-11.jpg",
        "..\/images\/items\/item-16\/img-12.jpg",
        "..\/images\/items\/item-16\/img-13.jpg",
        "..\/images\/items\/item-16\/img-14.jpg",
        "..\/images\/items\/item-16\/img-15.jpg",
        "..\/images\/items\/item-16\/img-16.jpg"

    ]

我也使用php sort()来排序文件的名称,但没有运气,任何帮助都将不胜感激,谢谢。

0 个答案:

没有答案