这是我的阵列:
Array (
[0] => Array ( [0] => content here [1] => 2010-02-04 01:25:34 )
[1] => Array ( [0] => content here [1] => 2010-02-04 04:51:37 )
[2] => Array ( [0] => content here [1] => 2010-02-04 04:52:31 )
[3] => Array ( [0] => content here [1] => 2010-02-04 05:50:48 )
[4] => Array ( [0] => content here [1] => 2010-02-04 03:25:34 )
[5] => Array ( [0] => content here [1] => 2010-02-04 05:39:33 )
[6] => Array ( [0] => content here [1] => 2010-02-04 03:25:34 )
[7] => Array ( [0] => content here [1] => 2010-02-04 07:07:09 )
[8] => Array ( [0] => content here [1] => 2010-02-04 07:07:23 )
[9] => Array ( [0] => content here [1] => 2010-02-04 08:51:18 )
)
如何按时间戳对其进行排序?
答案 0 :(得分:7)
function compare($e1, $e2) {
$t1 = strtotime($e1[1]));
$t2 = strtotime($e2[1]));
if($t1 == t2) {
return 0;
}
return ($t1 > $t2) ? 1 : -1;
}
usort($array, 'compare');
答案 1 :(得分:1)
使用usort()
和cmp_function
比较每个传递参数的索引1。
答案 2 :(得分:0)
答案 3 :(得分:0)
array_multisort()这是一个令人讨厌但功能强大的小功能。基本上你必须遍历你的数组,将日期戳拉出一个新的数组 - 维护密钥关联。然后,对新数组进行排序,仍然保持密钥关联。然后将新排序的数组和原始数组都抛出到array_multisort()中,原始数组将被排序为具有与排序数组相同顺序的键。
清除泥土?该doc页面上的示例应该有所帮助。
答案 4 :(得分:-1)
Bubble sort怎么样?
这意味着循环每个日期,检查前一个日期是否更大等等。