"Son değiştirilme tarihi" amacıyla bir dizindeki dosyaları listelemek için? (Linux PHP5)
function newest($a, $b)
{
return filemtime($a) - filemtime($b);
}
$dir = glob('files/*'); // put all files in an array
uasort($dir, "newest"); // sort the array by calling newest()
foreach($dir as $file)
{
echo basename($file).'<br />';
}
Kredi goes here.
Google'dan başka bir: http://www.php.net/manual/en/function.sort.php#76198
: Bir çözelti olacaktır
DirectoryIterator a> kullanarakSplFileInfo::getMTime a> kullanarak, onun son değişiklik zamanını almakasort or arsort a> ile ya dizi, sıralamak.
For example, this portion of code :
$files = array();
$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
$files[$fileinfo->getFilename()] = $fileinfo->getMtime();
}
}
arsort($files);
var_dump($files);
Bana verir:
array
'temp.php' => int 1268342782
'temp-2.php' => int 1268173222
'test-phpdoc' => int 1268113042
'notes.txt' => int 1267772039
'articles' => int 1267379193
'test.sh' => int 1266951264
'zend-server' => int 1266170857
'test-phing-1' => int 1264333265
'gmaps' => int 1264333265
'so.php' => int 1264333262
'prepend.php' => int 1264333262
'test-curl.php' => int 1264333260
'.htaccess' => int 1264333259
en son listenin başında modifiye, benim komut dosyası kaydedildiği dizindeki dosyaların listesini yani.