这个usort函数正在从我想要的方向返回数组。它返回一个数组(“1”,“2”,“3”)。如何返回(“3”,“2”,“1”)?
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"];
});
usort($myArray, function($a, $b) {
return $b["comments"] - $a["comments"];
});
只需将A更改为B,将B更改为A.
$myArray = array("1", "2", "3");
$reversed_array = array_reverse($myArray);
如果这些都不起作用,您可以随时发布命令两次,它将颠倒顺序。
usort($myArray, function($a, $b) {
return $a["comments"] - $b["comments"];
});
usort($myArray, function($a, $b) {
return $a["comments"] - $b["comments"];
});