按最大值排序多维数组/对象

5cg8jx4n  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(394)

我需要按最大值desc GROSS从最大值到最小最大值10结果的转换来排序此数组/对象
我要订购这个产品

array(19) {
  [0] => object(stdClass) #355 (8) { ["campaign_name"]= > string(27)
  "Scrub Viso Granuli Vegetali" ["campaign_id"] => int(14)["currency"] => string(3)
  "EUR" ["approvedConversions"] => int(0)["pendingConversions"] => int(0)["grossConversions"] => int(0)["payout"] => int(0)["pendingPayout"] => int(0)
} [1] => object(stdClass) #356 (8) { ["campaign_name"]= > string(33)
"Crema Viso/collo Acido Jaluronico" ["campaign_id"] => int(16)["currency"] => string(3)
"EUR" ["approvedConversions"] => int(0)["pendingConversions"] => int(0)["grossConversions"] => int(0)["payout"] => int(0)["pendingPayout"] => int(0)
} [2] => object(stdClass) #357 (8) { ["campaign_name"]= > string(13)
"Home Training" ["campaign_id"] => int(5)["currency"] => string(3)
"EUR" ["approvedConversions"] => int(0)["pendingConversions"] => int(0)["grossConversions"] => int(0)["payout"] => int(0)["pendingPayout"] => int(0)
} [3] => object(stdClass) #358 (8) { ["campaign_name"]= > string(25)
"4x Libri di apprendimento" ["campaign_id"] => int(4)["currency"] => string(3)
"EUR" ["approvedConversions"] => int(1)["pendingConversions"] => int(0)["grossConversions"] => int(2)["payout"] => int(15)["pendingPayout"] => int(0)
} [4] => object(stdClass) #359 (8) { ["campaign_name"]= > string(26)
"Tin-UP - Abbronzante Spray" ["campaign_id"] => int(11)["currency"] => string(3)
"EUR" ["approvedConversions"] => int(0)["pendingConversions"] => int(0)["grossConversions"] => int(0)["payout"] => int(0)["pendingPayout"] => int(0)
} [5] => object(stdClass) #360 (8) { ["campaign_name"]= > string(23)
"Aspirapolvere Ciclonica" ["campaign_id"] => int(22)["currency"] => string(3)
"EUR" ["approvedConversions"] => int(0)["pendingConversions"] => int(0)["grossConversions"] => int(0)["payout"] => int(0)["pendingPayout"] => int(0)
} [6] => object(stdClass) #361 (8) { ["campaign_name"]= > string(15)
"Centurion Power" ["campaign_id"] => int(12)["currency"] => string(3)
"EUR" ["approvedConversions"] => int(0)["pendingConversions"] => int(0)["grossConversions"] => int(0)["payout"] => int(0)["pendingPayout"] => int(0)
} [7] => object(stdClass) #362 (8) { ["campaign_name"]= > string(27)
"Tonico Te' Bianco Te' Rosso" ["campaign_id"] => int(10)["currency"] => string(3)
"EUR" ["approvedConversions"] => int(0)["pendingConversions"] => int(0)["grossConversions"] => int(0)["payout"] => int(0)["pendingPayout"] => int(0)
} [8] => object(stdClass) #363 (8) { ["campaign_name"]= > string(10)
"Air Freeze" ["campaign_id"] => int(13)["currency"] => string(3)
"EUR" ["approvedConversions"] => int(0)["pendingConversions"] => int(1)["grossConversions"] => int(3)["payout"] => int(0)["pendingPayout"] => int(16)
} [9] => object(stdClass) #364 (8) { ["campaign_name"]= > string(17)
"Monopattino Urban" ["campaign_id"] => int(25)["currency"] => string(3)
"EUR" ["approvedConversions"] => int(0)["pendingConversions"] => int(0)["grossConversions"] => int(0)["payout"] => int(0)["pendingPayout"] => int(0)
}
}

如何按最大值总换算说明订购?我试过了

function cmp($a, $b) {
                if ($a['grossConversions'] == $b['grossConversions']) {
                    return 0;
                }
                return ($a['grossConversions'] < $b['grossConversions']) ? 1 : -1;
            }

            uasort($getReportCampaign->records, 'cmp');

但是我得到了这个错误
致命错误:未捕获错误:无法将stdclass类型的对象用作中的数组

zaq34kh6

zaq34kh61#

数组中的所有行都是标准对象。我想你已经完成了json_解码
所以不是这个

$a['grossConversions']

那样做

$a->grossConversions

或者,如果要使用数组,请执行以下操作

json_decode(json_encode($my_array, true), true)

由于json_decode(cf docs)的真参数,它将stdclass“转换”为关联数组

相关问题