Created
January 14, 2016 18:13
-
-
Save iksi/ad330a760b78eef42c03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function compareFolderItems($a, $b) { | |
if (is_dir($a) && is_dir($b)) { | |
return strnatcasecmp($a, $b); | |
} | |
if (is_file($a) && is_file($b)) { | |
$compareExtensions = strcasecmp( | |
pathinfo($a, PATHINFO_EXTENSION), | |
pathinfo($b, PATHINFO_EXTENSION) | |
); | |
if ($compareExtensions === 0) { | |
return strnatcasecmp($a, $b); | |
} | |
return $compareExtensions; | |
} | |
if (is_dir($a) && is_file($b)) return -1; | |
if (is_file($a) && is_dir($b)) return 1; | |
} | |
function listFolderItems($folder) { | |
chdir($folder); | |
// Get directory items | |
$items = array_diff(scandir('.'), array('.', '..', '.DS_Store')); | |
// Folders, type and alphabetically | |
usort($items, 'compareFolderItems'); | |
return $items; | |
} | |
$items = listFolderItems('content'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment