我需要通过键值对数组php进行排序。我的阵列:
Array
(
[1430039342393636453] => Array
(
[0] => Array
(
[thrid] => 1430039342393636453
[uid] => 19748
[flag] => 1
[timestamp] => 1363791789
[date] => Mar 20
[content_preview] =>
[content] =>
)
)
[1430750471744336569] => Array
(
[0] => Array
(
[thrid] => 1430750471744336569
[uid] => 19870
[flag] => 1
[timestamp] => 1364469959
[date] => Mar 28
[content_preview] =>
[content] =>
)
[1] => Array
(
[thrid] => 1430750471744336569
[uid] => 19874
[flag] => 1
[timestamp] => 1364472417
[date] => Mar 28
[content_preview] =>
[content] =>
)
)
我需要按timestamp
主数组和子数组排序。
有什么建议吗?
答案 0 :(得分:1)
答案 1 :(得分:0)
尝试类似:
private function sort($sort) {
foreach($sort as &$arr) { //use a reference because usort uses references to manipulate your array.
//if you don't pass by reference you'll never see the sort
usort($arr, function($a, $b) { return $a['timestamp'] - $b['timestamp'];
}
usort($sort, function($a, $b) { return key($a) - key($b); }
return $sort;
}