0
PHP排序數組我有這樣的輸出:的關鍵
Array
(
[0] => Array
(
[id] => 4
[username] => bla1
)
[1] => Array
(
[id] => 5
[username] => bla2
)
[2] => Array
(
[id] => 6
[username] => bla3
)
)
我怎樣才能通過「用戶名」這外面陣列內的3個數組排序?
這是我的嘗試:
if($this->needOrder) {
$sorted = [];
foreach($files as $file) {
$sorted[] = asort($tableFile);
}
return $sorted;
}
$files
有^以上代碼的內容。 asort()
僅用於測試是否有效。 但我的回報是:
Array
(
[0] => 1
[1] => 1
[2] => 1
)
StackOveflow大約是來幫助你解決問題,你的實現。請提供您嘗試過的樣品,我們可以向您提供正確的方向。 – seebiscuit
你將不得不告訴我們你的目標是什麼!你也想看看這個:http://php.net/manual/en/array.sorting.php:D你可以嘗試自己弄清楚 – Rizier123
使用'usort'函數。寫一個比較函數,比較'$ a ['username']'和'$ b ['username']''。 – Barmar