Sorting array of folder list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Sorting array of folder list

Post by Peuplarchie »

Good day to you all,
I'm working on a script thta list folder in a specific folder.
My problem is that it won't sort.

Here is my code :

Code: Select all

 
 
 
    
        echo '<div style="width:620px; margin-left:auto; margin-right:auto; padding:0px; ">';
$dirr="Categories/".$cat."/".$val."/";
$dh  = opendir($dirr);
while (false !== ($filename = readdir($dh))) {
if ($filename != "." && $filename != "..") { // remove the move up directory commands. (. and ..)
    $files[] = $filename;
 
echo '<div style=" width:620px;  margin-left:auto; margin-right:auto; color:#FFFFFF; ">';
echo '<div style=" width:520px; margin-left:auto; margin-right:auto; color:#FFFFFF; float:left;"><img src="snippet_icon.png" border="0"/> '.$filename.'</div><br style="font-size:2px;"/>';
echo '<div style=" width:100px;  margin-left:auto; margin-right:auto; color:#FFFFFF; float:right; text-align:center;">';
echo '<a href="view_snippets.php" onclick="load(\'view_snippets.php?cat='.$cat.'&lang='.$val.'&code='.$filename.'\',\'page\');return false;" title="View Snippet '.$filename.'"><img src="view_icon.png" border="0" title="View Snippet '.$filename.'"/></a>';
echo '</div></div><br>';
}
}
sort ($files); // sort the file list in the array
 
 
echo "</div>";
 
echo "<br/><br/>";
 
 
 
 
 
 
Thanks!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Sorting array of folder list

Post by requinix »

glob doesn't get any lovin' nowadays.

(It'll sort the files for you.)
Post Reply