此usort函數正在從我想要的數組中返回數組。它返回一個數組,如(「1」,「2」,「3」)。我怎樣才能讓它返回(「3」,「2」,「1」)?usort正在以相反的順序返回數組
usort($myArray, function($a, $b) {
return $a["comments"] - $b["comments"];
});
此usort函數正在從我想要的數組中返回數組。它返回一個數組,如(「1」,「2」,「3」)。我怎樣才能讓它返回(「3」,「2」,「1」)?usort正在以相反的順序返回數組
usort($myArray, function($a, $b) {
return $a["comments"] - $b["comments"];
});
只是顛倒參數?
usort($myArray, function($a, $b) {
return $b["comments"] - $a["comments"];
});
你可以改變你的功能輸出。
usort($myArray, function($a, $b) {
return $b["comments"] - $a["comments"];
});
$myArray = array("1", "2", "3");
$reversed_array = array_reverse($myArray);
usort($myArray, function($a, $b) {
return $b["comments"] - $a["comments"];
});
只要改變A到B和B到A
謝謝哥們@Jelle – Mubin
'回報$ B [ 「意見」] - $ A [ 「意見」];' –