Jump to content


Photo

sorting files by date created?


  • Please log in to reply
2 replies to this topic

#1 jdubwelch

jdubwelch
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 26 April 2006 - 07:11 PM

i have a folder with 5 folders (engagement, explore, motion, motionless, and seniors). I'm going to use the $folders array to create links for the navigational part, but i don't want them to be ordered alphabetically.

I was thinking, if i could sort them by the time they were created or modified I could control it that way. I've search the net and haven't found anything.

How would I sort $folders array by the date the folders were created?

if ($handle = opendir('./files/')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $folders[] = $file;
        }
    }
    closedir($handle);
}

sort($folders);
print_r($folders);

will output this:

Array ( [0] => engagement [1] => explore [2] => motion [3] => motionless [4] => seniors )


#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 26 April 2006 - 10:16 PM

Look at the first two posts here

[a href=\"http://us2.php.net/function.rsort\" target=\"_blank\"]http://us2.php.net/function.rsort[/a]

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 koencalliauw

koencalliauw
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 26 April 2006 - 10:25 PM

try experimenting with the filectime() function

[a href=\"http://www.php.net/manual/en/function.filectime.php\" target=\"_blank\"]Function reference for filectime (php.net)[/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users