I have a file here that contains a list of database names and the corresponding size. Now I want to sort the size from largest to lowest, and the database name should go along it when showing. Using PHP here. Can someone help me?
Here is a simple code for this:
$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);
}
The file is as follows:
DatabaseName 300 KB
Note: $ data [1] contains dimensions. Should I place it on an array? what about db name?
The answers are much appreciated. =)
source
share