Entry
I am reading the contents of a directory into an array. How can I read them into the array in alphabetical order?
Mar 23rd, 2001 13:30
Ben Udall, Dave Martindale, http://www.php.net/manual/en/class.dir.php http://www.php.net/manual/en/function.natcasesort.php
You can't read the files into the array in alphabetical order, however,
you can sort the contents of the array after you read all the files.
$file_list = array();
$dir_obj = dir('.');
while ($item_name = $dir_obj->read())
$file_list[] = $item_name;
$dir_obj->close();
natcasesort($file_list);
foreach ($file_list as $filename)
echo htmlentities($filename)."<br />\n";