假设我有以下数组,如何在sort_by
上对其进行排序?
Array
(
[10] => Array
(
[Masthead_slide] => Array
(
[id] => 1456464564
[sort_by] => 1
)
)
[6] => Array
(
[Masthead_slide] => Array
(
[id] => 645454
[sort_by] => 10
)
)
[7] => Array
(
[Masthead_slide] => Array
(
[id] => 4547
[sort_by] => 5
)
)
)
答案 0 :(得分:1)
试试这个
function sortByOrder($a, $b) {
return $a['sort_by'] - $b['sort_by'];
}
usort($arr, 'sortByOrder');