$mass=[];
$mass['1']=95;
$mass['2']=98;
$mass['3']=54;
$mass['3']=3;
$mass['4']=78;
$mass['5']=34;
$mass['6']=78;
$new_arrey=[];
$i=0;
foreach ($mass as $key=>$val){
$new_arrey[$key]['val']=$val;
$new_arrey[$key]['n']=$i;
$i++;
}
$mass=$new_arrey;
uasort($mass, function ($a, $b) {
if ($a['val'] == $b['val']) {
if($a['n']>$b['n']) return 1;
if($a['n']<$b['n']) return -1;
}
if ($a['val'] > $b['val']) {
return 1;
}
else{
return -1;
}
});
foreach ($mass as $key=>$val){
$mass[$key]=$val['val'];
}
array(7) {
[7]=>
int(7)
[3]=>
int(64)
[4]=>
int(71)
[2]=>
int(83)
[6]=>
int(95)
[1]=>
int(95)
[5]=>
int(96)
}