You can use uksort()one that allows a custom callback to look at both keys and, indirectly, their associated values. Then it’s easy to decide which comparisons to make and return the corresponding value of greater than-less-than-or-zero to influence the sorting order.
(. ), , , .
$temp = $arr;
uksort($arr, function ($a,$b) use ($temp) {
if ($temp[$a] === $temp[$b]) {
return $a - $b;
}
return $temp[$b] - $temp[$a];
});
unset($temp);
print_r($arr);