排名php多维数组

I'm trying to rank a group of scores. So I've taken the input from a users form and sorted them from largest to smallest in a multidimensional array, so then that I can search the array for the user and retrieve the index to get its "rank" however I appear to be doing something totally wrong! any help on where I'm going wrong would be greatly appreciated, or if there is a better way entirely!

Thank you

PHP Code:

if ( isset( $_POST['submit'] ) ) {

    $size = $num_rows;
    $p = 0;
    $myarray = array();

    while ( $p < $size ) {
        $myarray[] = array( "user" => $user[$p], "data" => $scanrate[$p] );
        $p++;
    }

    $sort = array();

    foreach ( $myarray as $k => $v ) {
        $sort['data'][$k] = $v['data'];
    }

    array_multisort( $sort['data'], SORT_DESC, $myarray );

    for ( $i = 0; $i < $num_rows; $i++ ) {
        $key = array_search( $i, array_column( $myarray, 'user' ) );

        if ( !$key ) {
            $key = $num_rows;
        }
        //this is stored into my database
        echo "<br>User " . $user[$i] . " scan rate " . $scanrate[$i] . " rank " . $key;
    }
} 

You do useless code to do this sort, use the usort() function like :

while($p < $size)  
{ 
  $myarray[] = array("user" => $user[$p], "data" => $scanrate[$p]); 
  $p++; 
} 

usort($myarray, function($a, $b) {
    return $a['data'] - $b['data'];
});

Now your $myarray is sorted and you can search and do what you want.

If you're putting too much effort on smt. with a scripting language, you're definitely doing it wrong...

$sort = array_combine($user, $scanrate);
asort($sort);

// $sort is sorted now, used it as you like:

// List them
foreach ($sort as $user => $scanrate) {
    echo "<br>User " . $user . " scan rate " . $scanrate . " rank " . ++$i;
}

// Find the rank of specific user:
echo array_search('matt', array_keys($sort)) + 1;