Re: array order

From: Date: Fri, 29 Sep 2000 07:22:50 +0000
Subject: Re: array order
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-18008@lists.php.net to get a copy of this message
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 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

« previous php.general (#18008) next »