Posted by My Pet Programmer on 12/23/07 19:17
Big Moxy said:
> I have a routine to extract the name and mtime files in a directory.
> PHP by default sorts the array key. I looked at other sort functions
> but don't understand how to sort on a different field.
>
> Can someone please show me how to sort by the filemtime field instead
> of the filename?
>
> Thank you!
> Tim
>
> <TABLE ALIGN=CENTER BGCOLOR=#ffffff CELLPADDING=4 CELLSPACING=0
> border=2>
> <tr><TH>File</TH><TH>Date</TH></TR>
> <?php
> $dir="./";
> if (is_dir($dir)) {
> $dh = @opendir($dir);
> if($dh) {
> while (($file = @readdir($dh)) == true) {
> $pos = strpos($file, '.');
> if (!$pos === false) {
> if ($file != "." && $file != "..") {
> $file_array[] = $file;
> }
> }
> }
> }
> sort($file_array);
> reset($file_array);
> for($i=0;$i<count($file_array);$i++) {
> $name=$file_array[$i];
> $date = date("Y-m-d H:i", filemtime($name));
> if (!is_dir($name)) {
> print("<tr><TD>$name</TD><TD>$date</TD></TR>\n");
> }
> }
> }
> ?>
> </TABLE>
http://www.php.net/manual/en/function.asort.php
RTM
~A!
Navigation:
[Reply to this message]
|