PHP: Reverse Listing... reverse sort?

TommyWillB

Registered
Yes, I'm still quite the PHP newbie...

I have managed to swipe enough code from PHP.net to get some basic directoy listings working.

The directoy I am currently trying to list has folders with years (1999, 2000, 2001, etc.) What I'd like to have is the highest number year on top and the lowest on the bottom, but the standard directory listing does just the opposite.

I gather that you can walk the loop over the directory listing, build an array, reverse the array, and then reloop over the array to build the final HTML output.

Is there an easier way?

Here is what I've got so far to build list:
Code:
			// Listing just the folders...
			$DirectoryListing = dir($NewPath); //path defined higher up in code
			
			while (false !== ($entry = $DirectoryListing->read())) 
				{			
					if($entry != '.' && $entry != '..' && $entry != '.DS_Store' && $entry != $ThisFile)
						{
							if (is_dir("$NewPath$entry"))
								{
									print "$entry";
								}
						}
				}
			$DirectoryListing->close();

I'm not sure how long I'll keep my machine on, but here is my work in progress:
http://www.tomnjeff.com/digi_pix/index.php

Here is the straight HTML page I'm trying to automate:
http://www.tomnjeff.com/digi_pix/index.html
 
Well, yeah. The easier way is to read the directory into an array, then loop over the array in reverse order, processing and/or outputting each element.
 
Yep, and there's a nice function in PHP to reverse an array:

$reverse = array_reverse($array);
 
Back
Top