PHP multidimensional array (usort)
I have an associative array like this
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 ) ) I managed to sort it by the column I want (e.g. LastMonthSearchVolume)
// compare function function cmpi($a, $b) { return strcmp($a["lastMonthSearchVolume"], $b["lastMonthSearchVolume"]); } // do the array sorting usort($latest_array, 'cmpi'); The problem is when I dump the array to see the result that usort violated my associative array by deleting "News 1", "News 2", etc. and replacing it with 0,1,2 ...
Is there any sorting solution to keep the column name?
thanks