So, I\'m familiar with Javascript, HTML, and Python. I have never learned PHP, and at the moment, I\'m banging my head against my desk trying to figure out what (to me) seems t
I try your code and make simple changes and I am able to do what you want to get.
Here is my code ( copy of your code + Modify ) :
function listAlbums() {
$files = array();
if ($handle = opendir('./photos/')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
//echo $entry . "
";
$files[] = $entry;
}
}
closedir($handle);
}
// Sort your folder in ascending order
sort($files);
// Sort your folder in descending order [ code commented ]
//rsort($files);
// Check your photos folder has folder or not
if( !empty( $files ) ) {
// Show Your Folders
foreach ($files as $key => $folderName ) {
echo $folderName . "
";
}
} else {
echo 'You have no folder yet in photos directory';
}
}
My Changes:
You can know more about this from sort-and-display-directory-list-alphabetically-using-opendir-in-php
Thanks