我有一个看起来与此类似的数组:
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;
});
现在,我需要能够始终将人[Name] => House
放在阵列的顶部。我的想法是我可以将其排序Total
(因为我仍然需要这种方式),然后将具有 House 值的元素放在数组的开头。我可以取一个特定的 KEY 并将其放在顶部,但 KEY 可能会根据谁的总数最高而改变。我怎样才能始终将命名的人放在House
数组的顶部?