-2
我相信你很好。PHP - 按對象屬性排列對象數組
我想嘗試按對象的評分屬性對此數組進行排序。以下是數據的一個例子(print_r)。
Array
(
[0] => stdClass Object
(
[device] => 352454530452548
[reg] => MAM 432A
[distance] => 823.36
[ha_points] => 1
[hb_points] => 235
[hc_points] => 7.5
[idling_points] => 111.5
[speeding_points] => 168
[total] => 523
[score] => 68.239895064127
)
[1] => stdClass Object
(
[device] => 3518020541565265
[reg] => SM** ***
[distance] => 851.07
[ha_points] => 14
[hb_points] => 136
[hc_points] => 6
[idling_points] => 50
[speeding_points] => 336
[total] => 542
[score] => 68.957730856451
)
評分可以是0到100之間的任何值,我想按降序排列(最大的第一個?)。爲了使事情更復雜,雖然機會非常渺茫,但有可能得到兩個相同的分數,在這種情況下,哪一個並不重要。
任何想法?
由於提前,
保羅
你需要返回一個整數< 1, 0 or > 1,不是布爾! – deceze
輝煌,工作雖然我不得不改變回報爲$ a->得分< $b->得分,因爲它是升序。非常感謝歡呼! – Smithey93
@deceze:謝謝,忘了那個。無論誰加了'-',它都不能正常工作,因爲它們是浮動的,而且它們的區別將被舍入。 –