我正在構建一個WordPress網站,我需要在查詢已經運行之後對WP_User_Query的結果進行排序。對於那些你不熟悉,它看起來像這樣的內容:如何對包含對象的三維數組進行排序?
Array (
[0] => WP_User Object (
[data] => stdClass Object (
[ID] => 1
[user_login] => MarvinLazer
[user_pass] => $P$BUGHRCjMzlvn7dlGp53UTPC8GMF081/
[user_nicename] => marvinlazer
[user_email] => [email protected]
[user_url] => http://marvinlazer.com
[user_registered] => 2017-03-04 23:08:08
[user_activation_key] =>
[user_status] => 0
[display_name] => Marvin Lazer
)
[ID] => 1
[caps] => Array (
[subscriber] => 1
)
[cap_key] => wp_capabilities
[roles] => Array (
[0] => subscriber
)
[allcaps] => Array (
[read] => 1
[level_0] => 1
[subscriber] => 1
)
[filter] =>
)
[1] => WP_User Object (etc. etc.
基於this very helpful page on PHP array sorting,我覺得像我還挺近的東西。不幸的是,它只是在代碼出現的部分之後給我一個空白頁面。
function cmp(array $a, array $b) {
if ($a['data']['display_name'] < $b['data']['display_name']) {
return -1;
} else if ($a['data']['display_name'] > $b['data']['display_name']) {
return 1;
} else {
return 0;
}
}
usort($user_query->results, 'cmp');
任何人都想指出我對我做錯了什麼?
[訪問數組/對象](https://stackoverflow.com/a/30681087/6521116) –