How to save numeric key in multidimensional array after you sort it array_multisort?

Hello, Colleagues!
Help with a question, and it is this:

There is an array, like:
$products = array(
 25465 => array(
 'name' => 'blablabla',
 'rat' => 77
),
 12545 => array(
 'name' => 'blabla',
 'rat' => 55
 ),


trying to sort thus:
$ar_sort = array_map( function($n){
 return $n['rat'];
 }, 
$products
);
 array_multisort($ar_sort, SORT_DESC, SORT_STRING, $products);


the key is the ID of products, and they will not change or remove either as
accordingly, when sorting all these keys because they are numeric, overwritten, the question of how to do so if they remained. Once again, with an array of nothing to do

Forgot upamyanut, it is necessary to sort by a field rat inside the array
July 8th 19 at 12:21
2 answers
July 8th 19 at 12:23
Solution
Resolved the issue this way:
uasort($products, function($a, $b){
 $a = $a['rat'];
 $b = $b['rat'];
 if ($a == $b) {
 return 0;
}
 return ($a > $b) ? -1 : 1;
});
July 8th 19 at 12:25
Forgot upamyanut, it is necessary to sort by a field rat inside the array - estella_Stokes commented on July 8th 19 at 12:28

Find more questions by tags PHP