NYCPHP Meetup

NYPHP.org

[nycphp-talk] Listing files... alphabetically

Adam Maccabee Trachtenberg adam at trachtenberg.com
Tue Nov 25 16:33:40 EST 2003


On Tue, 25 Nov 2003, Adam Maccabee Trachtenberg wrote:

> On Tue, 25 Nov 2003, Robert Dumas wrote:
>
> > Here's the code I have. I left in a few commented lines, but don't hold that
> > against me.
>
> Your code works for me.

Actually, this is a lie. Your code lists files, but doesn't do them the
way (I think) you want them to.

You should be using ksort() instead of asort() since you're sorting on
the filename (which should be the array key) not the modified time
(which is the array value).

Also, you don't want to put \n inside single quotes. You should place
it inside double quotes, or it will be a literal \n and not a newline.

Last, check out natsort(), which will sort your numbers how you expect
them to sort. You may need to actually use uksort(), since there's no
knatsort(). Try: uksort($filetlist, 'strnatcmp');

-adam

-- 
adam at trachtenberg.com
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!



More information about the talk mailing list