Search code examples
phpdirectory-listing

PHP: Where to put rsort?


$count = 0;

if ($handle = opendir('./arkiv/')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $count++;
            print("<a href=\"arkiv/".$file."\">".basename($file, ".php")."</a><br />\n");
        }
    }
    echo '<br /><br /><a href=".">Tilbake</a>';
    closedir($handle);
}

This is the code I'm using, and I'm trying to figure out where to but 'rsort', but this is very new to me, can anyone help me?


Solution

  • Possible use can be like

    $count = 0;
             $fileArray = array();
             if ($handle = opendir('./arkiv/')) 
             {
                while (false !== ($file = readdir($handle))) 
                {
                   if ($file != "." && $file != "..") 
                   {  
                      $count++;
                      $fileArray[] = $file; 
    
                   }
                }
                rsort($fileArray);
                foreach($fileArray as $file)
                {
                   print("<a href=\"arkiv/".$file."\">".basename($file, ".php")."</a><br />\n");
                }
    
                echo '<br /><br /><a href=".">Tilbake</a>';
                closedir($handle);
             }
    

    Give it a try .... GOOD LUCK !!!