このような連想配列があります
Array
(
["News 1"] => Array
(
[text] => tests
[language] =>
[advertiserCompetitionScale] => 5
[avgSearchVolume] => 7480000
[lastMonthSearchVolume] => 9140000
)
["News 2"] => Array
(
[text] => personality tests
[language] =>
[advertiserCompetitionScale] => 5
[avgSearchVolume] => 165000
[lastMonthSearchVolume] => 201000
)
["News 3] => Array
(
[text] => online tests
[language] =>
[advertiserCompetitionScale] => 5
[avgSearchVolume] => 246000
[lastMonthSearchVolume] => 301000
)
)
必要な列で並べ替えることができました(たとえば、LastMonthSearchVolume)
// compare function
function cmpi($a, $b)
{
return strcmp($a["lastMonthSearchVolume"], $b["lastMonthSearchVolume"]);
}
// do the array sorting
usort($latest_array, 'cmpi');
問題は、配列をダンプして結果を確認すると、usort が「ニュース 1」、「ニュース 2」などを削除して連想配列を壊し、それを 0,1,2 に置き換えることです...
並べ替えを列名のままにする解決策はありますか?
ありがとう