PHP Files sorting by name

Files sorting by name

<?
$dir = "db";

$ar = array();
$handle = opendir($dir);

while($file = readdir($handle)) {
  if ($file != "." && $file != "..") { $ar[$file] = $file; }
}

if (isset($_GET['sort'])) {
  $sort = $_GET['sort'];
  if ($sort == "desc") { $a = "asc"; sort($ar); }
  if ($sort == "asc") { $a = "desc"; rsort($ar); }
}

echo "<A href='?sort=$a'>Name</A><BR><BR>";

foreach($ar as $show) echo "$show<BR>";
?>