Reply to Need help with sorting array

Your name:

Reply:


Posted by Big Moxy on 12/23/07 19:04

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>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация