Re: array order
| From: | Theodore Jones | Date: | Tue, 03 Oct 2000 02:39:19 +0000 |
| Subject: | Re: array order | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-18352@lists.php.net to get a copy of this message | ||
David Robley wrote:
> On Fri, 29 Sep 2000, Theodore Jones wrote:
> > Hello All,
> >
> > I have a script that iterates through a series of directories as such:
> >
> > 01-07-2000
> > 01-14-2000
> > 02-08-2000
> > 02-16-2000
> > 02-23-2000
> > 03-09-2000
> > 03-24-2000
> > 04-07-2000
> > 04-21-2000
> > 07-15-2000
> > 07-22-2000
> > 09-14-2000
> >
> > (directory named by date)
> >
> > when I read all these directories in with an opendir() function and feed them
> > into an array,
> > my display order seems to follow no logical order when the page comes out. For
> > example I would like the "latest" (09-14-2000) directory uploaded to show up at
> > the top of the list, and the "oldest" 01-07-2000 directory to appear at the
> > bottom of the list. Instead they display in no logical order...?
> >
> > Here's the portion of code I'm working with:
> >
> > $thumb_dir_handle = opendir($thumb_dir);
> > $a = 0;
> > while($file = readdir($thumb_dir_handle)) {
> > if((preg_match('/jpg/',$file)) ||
> > (preg_match('/png/',$file)) ||
> > (preg_match('/gif/',$file)) ||
> > (preg_match('/jpeg/',$file))) {
> > $file_array[$a] = $file;
> > $a++;
> > $file_count = count ($file_array);
> > }
> > }
> >
> > ... any ideas most greatfully solicited...
> >
> > Thanks,
> >
> > ~ Theo
>
> readdir will simply display the directories and files in the order (or lack
> of) that it finds them on the disk - you need to sort them into the order
> that you require by sorting the array. Now with a little modification of
> your directory structure to yyyy-mm-dd format, you could just do an rsort
> on the array to order the values descending.
David,
I tried to renaming the directories as per your suggestion, but still the same
result.. the directories don't get displayed with any chronological order. I even
checked the file-creation dates of the directories and couldn't find and order
there... any further suggestions? How can I find the order in which they are found
on the disk?
~ Theo