lm_a_dope Posted March 19, 2010 Share Posted March 19, 2010 hello i have this script that outputs all directory's and files the problem i am having is i can sort alphabetically say i have a file named a1 a2 a10 a3 the way it is sorting them is like this a1 a10 a2 a3 but i want to sort them like this a1 a2 a3 a10 here is my script please help its driving me nutty <?php function Treemenu($path) { //using the opendir function $dir_handle = @opendir($path) or die("Unable to open $path"); //Leave only the lastest folder name $dirname = end(explode("/", $path)); $TEST = array(); $i=0; //display the target folder. echo ("<li>$dirname\n"); echo "<ul>\n"; while (false !== ($file = readdir($dir_handle))) { if($file!="." && $file!="..") { if (is_dir($path."/".$file)) { //Display a list of sub folders. Treemenu($path."/".$file); } else { //Display a list of files. $TEST[$i] = "<li><a href=\"{$path}/{$file}\">" .str_replace('.htm','',$file). "</a></li>"; $i++; } } } sort($TEST); echo implode('', $TEST); echo "</ul>\n"; echo "</li>\n"; //closing the directory closedir($dir_handle); } Treemenu('games') ?> Link to comment https://forums.phpfreaks.com/topic/195789-need-help-sorting-alphabetically-and-numerically/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 19, 2010 Share Posted March 19, 2010 http://us3.php.net/manual/en/function.natcasesort.php Link to comment https://forums.phpfreaks.com/topic/195789-need-help-sorting-alphabetically-and-numerically/#findComment-1028517 Share on other sites More sharing options...
lm_a_dope Posted March 19, 2010 Author Share Posted March 19, 2010 thank you something so simple was driving me crazy Link to comment https://forums.phpfreaks.com/topic/195789-need-help-sorting-alphabetically-and-numerically/#findComment-1028524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.