note 54227 added to function.rsort

From: Date: Tue, 28 Jun 2005 02:39:05 +0000
Subject: note 54227 added to function.rsort
Groups: php.notes 
Request: Send a blank email to php-notes+get-91045@lists.php.net to get a copy of this message
A cleaner (I think) way to sort a list of files into reversed order based on their modification date. <?php $path = $_SERVER[DOCUMENT_ROOT]."/files/"; $dh = @opendir($path); while (false !== ($file=readdir($dh))) { if (substr($file,0,1)!=".") $files[]=array(filemtime($path.$file),$file); #2-D array } closedir($dh); if ($files) { rsort($files); #sorts by filemtime #done! Show the files sorted by modification date foreach ($files as $file) echo "$file[0] $file[1]<br>\n"; #file[0]=Unix timestamp; file[1]=filename } ?> ---- Manual Page -- http://www.php.net/manual/en/function.rsort.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54227 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54227&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54227&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54227&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54227&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54227&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54227&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54227&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91045) next »