排序键的排列基部 [英] sort an array base on key
本文介绍了排序键的排列基部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的数组:
Array
(
[0] => Array
(
[title] => some title
[time] => 1279231500
)
[1] => Array
(
[title] => some title 2
[time] => 1279231440
)
[2] => Array
(
[title] => some title 3
[time] => 1279229880
)
)
我怎么能根据时间排序呢?
how i can sort it based on time?
推荐答案
您可以用这种方式对它进行排序(因为它是一个关联数组):
You can sort it this way (since it is an associative array):
function cmp($a, $b)
{
return strcmp($a['time'], $b['time']);
}
usort($your_array, "cmp");
print_r($your_array);
这篇关于排序键的排列基部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文