note 104150 deleted from function.scandir by cmb
| From: | cmb@php.net | Date: | Sun, 17 Nov 2019 09:05:34 +0000 |
| Subject: | note 104150 deleted from function.scandir by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213119@lists.php.net to get a copy of this message | ||
Note Submitter: Gerjoo at gmail dot com
----
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