function Listfolders ()
{
Set a path
$dir = "./";
Set up an array of file pieces
$aDir = Array ();
$oCurrentdir = Opendir ($dir); Open Directory
while ($sFile = Readdir ($oCurrentdir))//Read all subdirectories of the current directory
{
if ($sFile!= '. ' && $sFile!= ' ... ' && is_dir ($dir. $sFile))//To determine whether it is the root directory
$aFolders [] = ' directory: '. $sFile. ' <br/> '/The list of the Lost
}
Closedir ($oCurrentdir);//Judge the directory you just opened with Opendir
Open the "Folders" node.
Natcasesort ($aFolders); Natural order case-insensitive for an array sorting the elements in the given arrays, that is, sorting the numbers from 1 to 9, sorting the letters from A to Z, the short priority
foreach ($aFolders as $sFolder)
{
Echo $sFolder;
}
}
/*
Test, we have two subdirectories in the current directory
Table of Contents: 1
Table of Contents: www.111cn.net
*/
Getfolders ();
/*
After running, the results are
Table of Contents: 1
Table of Contents: www.111cn.net
Common function parsing:
Array () data declaration, you can use Direct Assignment array (1,2,3,4);
Opendir () Opens the directory, and the Opendir () function opens a directory handle that can be used by Closedir (), Readdir (), and Rewinddir () and, if successful, returns a directory stream, or false and an error. You can hide the output of an error by adding "@" in front of the function name.
Readdir Read Directory
Cosedir Judgment Catalogue
The Natcasesort () function sorts the elements in a given array with a case-insensitive natural order algorithm. The Natcasesort () function implements a "natural sort", the sort method of numbers from 1 to 9, the sorting method of letters from A to Z, the short precedence, and the function is case-insensitive. The index of an array remains associated with the cell value. If successful, the function returns TRUE, otherwise it returns FALSE.
Site finishing and original reprint annotated from Www.111cn.net