note 104150 added to function.scandir

From: Date: Thu, 26 May 2011 18:41:53 +0000
Subject: note 104150 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-180061@lists.php.net to get a copy of this message
If you wish to sort by folders first then files, you could use something like this: <?php function scandirSorted($path) { $sortedData = array(); foreach(scandir($path) as $file) { if(is_file($path . $file)) { array_push($sortedData, $file); } else { array_unshift($sortedData, $file); } } return $sortedData; } ?> NB.: This approach *might* be suboptimal for high performance situations. - Gerard ---- Server IP: 83.137.20.135 Probable Submitter: 83.87.181.228 ---- Manual Page -- http://www.php.net/manual/en/function.scandir.php Edit -- https://master.php.net/note/edit/104150 Del: integrated -- https://master.php.net/note/delete/104150/integrated Del: useless -- https://master.php.net/note/delete/104150/useless Del: bad code -- https://master.php.net/note/delete/104150/bad+code Del: spam -- https://master.php.net/note/delete/104150/spam Del: non-english -- https://master.php.net/note/delete/104150/non-english Del: in docs -- https://master.php.net/note/delete/104150/in+docs Del: other reasons-- https://master.php.net/note/delete/104150 Reject -- https://master.php.net/note/reject/104150 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180061) next »