我在 CakePHP 框架内工作,并且有以下多维数组,我需要按值排序。我正在使用usort
,但无法弄清楚如何按[ForumPost]
.
这是数组:
Array
(
[0] => Array
(
[ForumPost] => Array
(
[id] => 174
[forum_id] => 81
[user_id] => 39
[title] => A test post
[1] => Array
(
[ForumPost] => Array
(
[id] => 64
[forum_id] => 208
[user_id] => 36
[title] => B test post
... etc
我的功能和调用是:
usort($array, array("ForumSearchesController", "cmp"));
function cmp($a, $b) {
return $a['ForumPost']['title'] - $b['ForumPost']['title'];
}