ianco Posted February 10, 2010 Share Posted February 10, 2010 Hi all I have some code that displays the contents of each file from a given folder. The thing is it displays files alphabetically. I want to do the opposite (z to a). I've played around with the asort() function and can't seem to get it right. Doe's anyone have a solution? Thanks Ian <?php if ($handle = opendir('./files/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { include("./files/" . $file); echo "<br>"; } } closedir($handle); } ?> Link to comment https://forums.phpfreaks.com/topic/191606-sorting-files-in-reverse/ Share on other sites More sharing options...
trq Posted February 10, 2010 Share Posted February 10, 2010 $arr = array_reverse(glob('./files/*')); foreach ($arr as $file) { include "./files/$file"; echo "<br>"; } Link to comment https://forums.phpfreaks.com/topic/191606-sorting-files-in-reverse/#findComment-1010018 Share on other sites More sharing options...
ianco Posted February 10, 2010 Author Share Posted February 10, 2010 and do i use this code to replace my code or add it in? Doesn't seem to work on its own. Should there be brackets for the include()? Link to comment https://forums.phpfreaks.com/topic/191606-sorting-files-in-reverse/#findComment-1010024 Share on other sites More sharing options...
trq Posted February 10, 2010 Share Posted February 10, 2010 Sorry, this should work. $arr = array_reverse(glob('./files/*')); foreach ($arr as $file) { include $file; echo "<br>"; } include is not a function so doesn't need brackets. Oh, and it replaces your code. Link to comment https://forums.phpfreaks.com/topic/191606-sorting-files-in-reverse/#findComment-1010025 Share on other sites More sharing options...
ianco Posted February 10, 2010 Author Share Posted February 10, 2010 That's cracked it, cheers Ian Link to comment https://forums.phpfreaks.com/topic/191606-sorting-files-in-reverse/#findComment-1010026 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.