我有这种格式的数组:
Array ( [0] => Array ( [text] => tests [language] => [advertiserCompetitionScale] => 5 [avgSearchVolume] => 7480000 [lastMonthSearchVolume] => 9140000 ) [1] => Array ( [text] => personality tests [language] => [advertiserCompetitionScale] => 5 [avgSearchVolume] => 165000 [lastMonthSearchVolume] => 201000 ) [2] => Array ( [text] => online tests [language] => [advertiserCompetitionScale] => 5 [avgSearchVolume] => 246000 [lastMonthSearchVolume] => 301000 ) )
如何按该avgSearchVolume字段的降序对该格式的数组排序?是否有内置功能?
avgSearchVolume
使用usort并提供您自己的功能进行订购,例如
usort
function cmp($a, $b) { return $b['avgSearchVolume'] - $a['avgSearchVolume']; } usort($array, "cmp");