Re: array order
| From: | David Robley | Date: | Tue, 03 Oct 2000 05:54:02 +0000 |
| Subject: | Re: array order | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-18368@lists.php.net to get a copy of this message | ||
On Tue, 03 Oct 2000, Theodore Jones wrote:
<Sort an array of directories named dd-mm-yyyy>
> > > 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
> >
> > Well, like I said, the directory listing is in no particular order. What
> > you'll need to do is put all the directory names in an array, and then use
> > rsort to sort the array in reverse order, then you can list the array
> > elements in the desired format.
>
> David,
>
> Thanks for the offer of help, but like I said, I >am< feeding them into and array, and
> the order in which the array is created makes absolutely no sense. Any sort funtion on
> the array then has zilch effect, because they're in no particular order order to it in
> the first place. I'm just trying to figure out why it comes out the way it does now,
> wich apperently may have no answer?
>
> ~ Theo
Hmm - forgot we're sorting strings here :-) so your secondary sorts on the
month and day may be a bit confusing in spots. Maybe the rename of the
directories should be strict yyyymmdd with zero fill to get the sort
correct.
This snippet of code will show you the difference.
<?php
$dirlist[]= '2000-12-30';
$dirlist[]= '1996-2-3';
$dirlist[]= '1947-11-21';
$dirlist[]= '2001-10-8';
$dirlist[]= '1957-9-13';
$dirlist[]= '1983-1-27';
$dirlist[]= '1997-2-11';
$dirlist[]= '1994-7-24';
$dirlist[]= '1997-3-18';
$dirlist[]= '2000-9-16';
rsort($dirlist);
while(list(,$val)= each($dirlist)) {
echo $val .'<BR>';
}
echo '<HR>';
unset($dirlist);
$dirlist[]= '20001230';
$dirlist[]= '19960203';
$dirlist[]= '19471121';
$dirlist[]= '20011008';
$dirlist[]= '19570913';
$dirlist[]= '19830127';
$dirlist[]= '19970211';
$dirlist[]= '19940724';
$dirlist[]= '19970318';
$dirlist[]= '20000916';
rsort($dirlist);
while(list(,$val)= each($dirlist)) {
echo $val .'<BR>';
}
?>
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA
-------------------------------------------------------
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA