BetaArchive Logo
Navigation Home Screenshots Image Uploader Server Info FTP Servers Wiki Forum RSS Feed Rules Please Donate
UP: 4d, 8h, 5m | CPU: 48% | MEM: 2192MB of 4389MB used
{The community for beta collectors}

Forum rules


Any off topic discussions should go in this forum. Post count is not increased by posting here.
FTP Access status is required to post in this forum. Find out how to get it


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPost subject: Read each file in a directory backwards in PHP        Posted: Mon Aug 11, 2008 11:49 am 
Reply with quote
Donator
User avatar
Offline

Joined
Fri May 18, 2007 9:39 am

Posts
953

Location
My house
I know that you can read each file in a directory using the readdir command, but is there any way you can read it in backwards alphabetical order?

_________________
Image


Top  Profile
 PostPost subject:        Posted: Tue Aug 19, 2008 7:37 pm 
Reply with quote
craig wrote:
Try something like this...

Code:
$handle = opendir('/');
while($data = readdir($handle)){
   $array[] = $data;
}
$reverse = array_reverse($array);

foreach ($reverse as $filename){
   echo $filename.'<br>';
}


So what your doing is setting the values to an arrray, then reversing the array.


but i think you can better add !== false

like

Code:
$handle = opendir('/');
while(($data = readdir($handle)) !== false){
   $array[] = $data;
}
$reverse = array_reverse($array);

foreach ($reverse as $filename){
   echo $filename.'<br>';
}

i don`t know exactly why :P but in many scripts it is and i think its better :)


Top
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 




Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron

All views expressed in these forums are those of the author and do not necessarily represent the views of the BetaArchive site owner.

Powered by phpBB® Forum Software © phpBB Group

Copyright © 2006-2018

 

Sitemap | XML | RSS