sorting - PHP Scandir Not Automatically in Alphabetical Order? -
tia. remedial php skills, can't figure out why scandir isn't automatically sorting alphabetically. (it nice have folders grouped , sorted alphabetically , files grouped , sorted alphabetically, isn't critical.) missing?
<?php $dir = './customers/' . $customer . "/"; $exclude = array(".","..",".htaccess"); if (is_dir($dir)) { $files = scandir($dir); foreach($files $key=>$dir){ if(!in_array($dir, $exclude)){ echo ("<a href=\"./customers/$customer/".$dir."\">".$dir."</a><br>"); } } } ?>
as wgd said, must use natcasesort following way:
$files = scandir($dir); natcasesort($files); foreach ($files $file) { // code }
Comments
Post a Comment