uksort($arr, function ($a, $b) use ($arr) {
return $arr[$a] - $arr[$b] ?: $a - $b;
});
You can get the values by the keys, so use uksort which gives you the keys. Replace $a - $b with your appropriate magic, here it's just sorting by the key's value.