FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » sorting readdir output?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: sorting readdir output? [message #184006 is a reply to message #184003] Sun, 01 December 2013 18:19 Go to previous messageGo to previous message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma:
Senior Member
On Sun, 1 Dec 2013 18:10:09 -0000, James Harris wrote:

> "Lew Pitcher" <lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote in message
> news:vOKmu(dot)376035$jg4(dot)217970(at)fx05(dot)iad...
>
> ...
>
>>> if ($handle = opendir('../audio/1960/')) {
>
> ...
>
>>> while (false !== ($entry = readdir($handle))) {
>>> echo "$entry\n<br>";
>>> }
>
> ...
>
>>> This gives the output in an unsorted list.
>>> How can I make it so the array is sorted?
>
> ...
>
>> As you read the directory, put each entry into the same array.
>> Once you've hit the end, sort the array.
>
> How about using scandir?
>
> $ents = scandir($document_root . $dir);
> natcasesort($ents);
>
> James

This one does what I want nicely.
thanks.

<?php
$dir = "/tmp";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}

sort($files);

print_r($files);

rsort($files);

print_r($files);

?>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: dropdown menus
Next Topic: Re: SEO SERVICES
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 07:18:14 GMT 2024

Total time taken to generate the page: 0.04043 seconds