I am having MAJOR usort() issues! :( So basically I want to sort my array by their values. I would like the values to display in this order: Platinum, Gold, Silver, Bronze, Complete, None, Uncomplete. Now I can sort them well, but I would like to preserve their key (is that possible?). here is my code:
function compareMedals( $a, $b ) {
$aMap = array(1 => 'Platinum', 2 => 'Gold', 3 => 'Silver', 4 => 'Bronze', 5 => 'Complete', 6 => 'None', 7 => 'Uncomplete');
$aValues = array( 1, 2, 3, 4, 5, 6, 7);
$a = str_ireplace($aMap, $aValues, $a);
$b = str_ireplace($aMap, $aValues, $b);
return $a - $b;
}
usort($list, 'compareMedals');
So is it possible to sort them WHILE preserving their keys? Thank You! :)
EDIT
Array:
$array = array("post1" => 'Platinum', "Post2" => "Bronze, "Post3" = > Gold)
Should output:
"Post1" => 'Platinum',
"Post3" => 'Gold',
"Post2" => 'Bronze'
Yet it is outputting this:
"0" => 'Platinum',
"1" => 'Gold',
"2" => 'Bronze'