php对于数组内某元素大小重新排列

Array
(
    [0] => Array
        (
            [Name] => Anan Ryoko - Refrain.mp3
            [fullName] => Anan Ryoko - Refrain.mp3
            [length] => 6437585
            [uploadTime] => 1422975265
        )

    [1] => Array
        (
            [Name] => Andemund Orchestra - 梦中的婚礼.mp3
            [fullName] => Andemund Orchestra - 梦中的婚礼.mp3
            [length] => 1647776
            [uploadTime] => 1422975357
        )

    [2] => Array
        (
            [Name] => Ashram - Elizabeth.mp3
            [fullName] => Ashram - Elizabeth.mp3
            [length] => 1865495
            [uploadTime] => 1422975376
        )

    [3] => Array
        (
            [Name] => Bandari - 山溪.mp3
            [fullName] => Bandari - 山溪.mp3
            [length] => 3304113
            [uploadTime] => 1422975391
        )

)

我想对数组里的uploadTime进行重新排列,代码如下

<?php
array=Array
(
    '0' => Array
        (
            'Name' => 'Anan Ryoko - Refrain.mp3',
            'fullName' => 'Anan Ryoko - Refrain.mp3',
            'length' => '6437585',
            'uploadTime' => '1422975265',
        ),

    '1' => Array
        (
            'Name' => 'Andemund Orchestra - 梦中的婚礼.mp3',
            'fullName' => 'Andemund Orchestra - 梦中的婚礼.mp3',
            'length' => '1647776',
            'uploadTime' => '1422975357',
        ),

    '2' => Array
        (
            'Name' => 'Ashram - Elizabeth.mp3',
            'fullName' => 'Ashram - Elizabeth.mp3',
            'length' => '1865495',
            'uploadTime' => '1422975376',
        ),

    '3' => Array
        (
            'Name' => 'Bandari - 山溪.mp3',
            'fullName' => 'Bandari - 山溪.mp3',
            'length' => '3304113',
            'uploadTime' => '1422975391',
        ),
);
foreach(array as key =>row){  
    uploadTime[key] = row['uploadTime'];  
}  
array_multisort(uploadTime,SORT_DESC,array);
print_r (array);

输出

Array
(
    [0] => Array
        (
            [Name] => Bandari - 山溪.mp3
            [fullName] => Bandari - 山溪.mp3
            [length] => 3304113
            [uploadTime] => 1422975391
        )

    [1] => Array
        (
            [Name] => Ashram - Elizabeth.mp3
            [fullName] => Ashram - Elizabeth.mp3
            [length] => 1865495
            [uploadTime] => 1422975376
        )

    [2] => Array
        (
            [Name] => Andemund Orchestra - 梦中的婚礼.mp3
            [fullName] => Andemund Orchestra - 梦中的婚礼.mp3
            [length] => 1647776
            [uploadTime] => 1422975357
        )

    [3] => Array
        (
            [Name] => Anan Ryoko - Refrain.mp3
            [fullName] => Anan Ryoko - Refrain.mp3
            [length] => 6437585
            [uploadTime] => 1422975265
        )

)

完成~~

参考资料

w3schoolhttp://www.w3school.com.cn/php/func_array_multisort.asp

PHP Manualhttp://cn2.php.net/manual/zh/function.array-multisort.php

php对于数组内某元素大小重新排列》有3个想法

发表评论

电子邮件地址不会被公开。 必填项已用*标注