How to sort array from file (PHP)?
<p>I have a file here which contains list of database names and its corresponding size.
Now I want to sort the size from the largest to the lowest, and the database name
should go along it upon display.Am using PHP here..
Can anyone help me out? </p>

<p>Here's a simple code for that:</p>

<pre><code>$file_name = test.txt
$handle = @fopen($file_name, "r");

if ($handle) {
    while (!feof($handle)) {

    $buffer = fgets($handle, 4096);
        $data = explode(" ",$buffer);
       echo $data[1]."\n";
    }
    fclose($handle);
}
</code></pre>

<p>File looks like this:</p>

<pre><code>DatabaseName 300 KB
</code></pre>

<p>Note: $data[1] contains the sizes. Should i place it on an array? how about the db name?</p>

<p>Answers are very much appreciated. =)</p>
