note 60498 deleted from function.scandir by felipe

From: Date: Fri, 29 Aug 2008 23:24:09 +0000
Subject: note 60498 deleted from function.scandir by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143996@lists.php.net to get a copy of this message
Note Submitter: colabus at gmail dot com ---- I made a small dir listing based on file modification date, could find alot on this myself so I hope this helps someone. <? $dirView="./blah"; $dirFiles=scandir($dirView); $cwdName=array(); $cwdMod=array(); $whatWeNeed=array(); // Parallel arrays (ignore the ".", ".." and inturn hidden files foreach ($dirFiles as $data) { if (!preg_match('/^\./', $data)) { $cwdName[]=$data; $cwdMod[]=filemtime($dirView."/".$data); } } // Merge and sort $mergeArray=array_combine($cwdMod, $cwdName); krsort($mergeArray, SORT_NUMERIC); // Build new array foreach ($mergeArray as $key => $value) { $whatWeNeed[]=$value; } // Some maintainence unset($dirFiles, $cwdName, $cwdMod, $mergeArray); # Then can grab latest changed file/folder with whatWeNeed[0] and so on.. ?> Tested with error_reporting(E_ALL); and PHP5.1

« previous php.notes (#143996) next »