开发者

Sort array by Alpha?

开发者 https://www.devze.com 2023-01-21 01:40 出处:网络
Code below takes a directory and creates an array of folder names appearing under the directory. How can order the folder names inside the array by alpha?

Code below takes a directory and creates an array of folder names appearing under the directory. How can order the folder names inside the array by alpha?

function get_dirs($dir) {
   $array = array();
   $d = dir($dir);
   while (false !== ($entry = $d->read())) {
       if($entry!='.' && $entry!='..') {
           $entry2 = $dir."/".$entry;
           if(is_dir($entry2)) {
               $array[] = $entry;
           }
       }
   }
   $d->close();
   return $array;
}
开发者_高级运维


I believe sort($array); should do the trick: http://us.php.net/manual/en/function.sort.php


You can use sort($array)

Or rsort() if you want it in descending order.

0

精彩评论

暂无评论...
验证码 换一张
取 消