如何首先按数字索引对$ _FILES进行排序?

时间:2017-01-17 17:42:23

标签: php file sorting

当上传多个文件时,PHP会对文件进行排序:

Array
(
    [name] => Array
        (
            [0] => game-of-thrones-series-1080p-hd-wallpaper-movies.jpg
            [1] => HD-Hitman-Wallpaper.jpg
            [2] => New-Games-Wallpapers-Full-HD-1080p.jpg
        )

    [type] => Array
        (
            [0] => image/jpeg
            [1] => image/jpeg
            [2] => image/jpeg
        )

    [tmp_name] => Array
        (
            [0] => C:\xampp\tmp\php7659.tmp
            [1] => C:\xampp\tmp\php765A.tmp
            [2] => C:\xampp\tmp\php766A.tmp
        )

    [error] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
        )

    [size] => Array
        (
            [0] => 579476
            [1] => 1006801
            [2] => 532174
        )
)

我想先按文件编号对文件进行排序,如下所示:

Array
(
    [0] => Array
        (
            [name] => game-of-thrones-series-1080p-hd-wallpaper-movies.jpg
            [type] => image/jpeg
            [tmp_name] => C:\xampp\tmp\php7659.tmp
            [error] => 0
            [size] => 579476
        )

    [1] => Array
        (
            [name] => HD-Hitman-Wallpaper.jpg
            [type] => image/jpeg
            [tmp_name] => C:\xampp\tmp\php765A.tmp
            [error] => 0
            [size] => 1006801
        )

    [2] => Array
        (
            [name] => New-Games-Wallpapers-Full-HD-1080p.jpg
            [type] => image/jpeg
            [tmp_name] => C:\xampp\tmp\php766A.tmp
            [error] => 0
            [size] => 532174
        )
)

我知道可以通过使用foreach循环来完成,但我正在寻找一种更简单有效的方法。不知道怎么办呢?

0 个答案:

没有答案