这应该很简单,但是如何进行呢? 我想通过键对多维数组进行排序,如下所示:
Array (
[0] => Array
(
[iid] => 1
[invitee] => 174
[nid] => 324343
[showtime] => 2010-05-09 15:15:00
[location] => 13
[status] => 1
[created] => 2010-05-09 15:05:00
[updated] => 2010-05-09 16:24:00
)
[1] => Array
(
[iid] => 1
[invitee] => 220
[nid] => 21232
[showtime] => 2010-05-09 15:15:00
[location] => 12
[status] => 0
[created] => 2010-05-10 18:11:00
[updated] => 2010-05-10 18:11:00
))
假设我想按 [status] 排序,我该如何实现? 提前致谢!
最佳答案
//define a comparison function
function cmp($a, $b) {
if ($a['status'] == $b['status']) {
return 0;
}
return ($a['status'] < $b['status']) ? -1 : 1;
}
usort($array, "cmp");
这应该做你想做的,你可以改变比较函数来排序你想要的任何键。
关于php - 如何按某个键对多维数组进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2804690/