How can I order a table in a loop depending on the highest number in a specific <td>

How can I order lines of a table depending on the highest number in a loop like this :

<?php
while ($d = $data->fetch()) {
$champs_files = fopen("champions/".$champion."_".$d['user_id'].".txt", "r");
$mastery_points = fread($champs_files,filesize("champions/".$champion."_".$d['user_id'].".txt"));
fclose($champs_files);
?>
<tr>
    <td><?= $rank += 1 ?></td>

        <td><?= $d['user_name'] ?></td>

        <td><?= $mastery_points ?></td>

        <td><?= $d['user_region'] ?></td>

    </tr>
<?php
}
?>

I want to put at the top the line who has the biggest $mastery_points .

I can’t use MySql cause I have limited number of tables thats why I use files .


Source: stackoverflow-php

Join multiple arrays of order indexes

Using javascript, I have multiple arrays of indexes, representing an order:
[[0,1,2], [2,0,1], [1,2,0], [0,1,2], ...]
I need to join to a single sequential array keeping the order of the input. This would be the output of the input above:
[0,1,2,5,3,4,7,8,6,9,10,11, ...]
Thanks.


Source: stackoverflow-javascript