数组按时间戳排序 PHP [英] Array Sorting PHP by timestamp

查看:35
本文介绍了数组按时间戳排序 PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在按照我想要的方式排序数组时遇到问题.

I have problem ordering an array in the way I want.

这是我的数组的示例输出:

This is an example output of my array:

# 159 rows in total
Array
(
    [0] => Array
        (
            [0] => pastebin
            [1] =>  
            [2] => 1305025723
            [3] => /fcTGqQGD
        )
 
    [1] => Array
        (
            [0] => pastebin
            [1] =>  
            [2] => 1305025723
            [3] => /YQNk8yqa
        )
 
    [2] => Array
        (
            [0] => pastebin
            [1] =>  
            [2] => 1305025723
            [3] => /u2BNPrad
        )
 
    [3] => Array
        (
            [0] => pastebin
            [1] =>  
            [2] => 1305025722
            [3] => /d/blogdialain.com
        )
 
    [4] => Array
        (
            [0] => pastebin
            [1] =>  
            [2] => 1305025722
            [3] => /d/shopcraze.com
        )
 
    [5] => Array
        (
            [0] => pastebin
            [1] =>  
            [2] => 1305025722
            [3] => /domains_archive/175
        )
 
    [6] => Array
        (
            [0] => pastebin
            [1] =>  
            [2] => 1305025722
            [3] => /d/togou.com
        )
 
    [7] => Array
        (
            [0] => pastebin
            [1] =>  
            [2] => 1305025722
            [3] => /W6NafmJa
        )
)

在此处完成阵列数据:http://pastebin.com/GJNBmqL7

数据同时来自各种数据库,所以我将数据放入数组的方式受到限制.

Data comes from various database at once, so I'm limited in the way that I put the data into the array.

[2] 总是包含一个 linux 时间戳.现在我希望整个数组按该时间戳排序,最低值在前.

The [2] always contains a linux timestamp. Now I want the entire array to be ordered by that timestamp, with the lowest value first.

我怎样才能做到这一点?

How can I get that done?

推荐答案

这里有一个 array_multisort 示例:

foreach ($array as $key => $node) {
   $timestamps[$key]    = $node[2];
}
array_multisort($timestamps, SORT_ASC, $array);

这篇关于数组按时间戳排序 PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆