我有一个类似于这样的数组:
Array
(
[0] => stdClass Object
(
[Leasing] => 12939.74
[Name] => Jeremy
[Rental] => 0
[Sales] => 56603.13
[Total] => 69542.87
)
[1] => stdClass Object
(
[Leasing] => 0
[Name] => Shaun
[Rental] => 0
[Sales] => 58590
[Total] => 58590
)
[2] => stdClass Object
(
[Leasing] => 0
[Name] => Lindsay
[Rental] => 0
[Sales] => 22951.97
[Total] => 22951.97
)
[3] => stdClass Object
(
[Leasing] => 0
[Name] => Sally
[Rental] => 1200
[Sales] => 21624.9
[Total] => 22824.9
)
[4] => stdClass Object
(
[Leasing] => 0
[Name] => House
[Rental] => 0
[Sales] => 16235.81
[Total] => 16235.81
)
[5] => stdClass Object
(
[Leasing] => 5298.85
[Name] => Bill
[Rental] => 1200
[Sales] => 0
[Total] => 6498.85
)
)
目前,使用以下方式按总数对数组进行排序:
usort($data, function ($a, $b) {
return $b->Total - $a->Total;
});
我需要始终使名为House
的人位于数组的顶部。 我的想法是保持按Total
排序(因为我仍然需要这样),然后将带有House
值的元素放在数组的开头。 我可以将特定的KEY放在顶部,但是KEY可能会根据谁拥有最高总数而改变。 如何始终将名为House
的人放在数组的顶部?