【发布时间】:2011-11-17 17:02:04
【问题描述】:
我正在使用 glob 来排列我的子目录
<?php
$items = glob("../albums/*", GLOB_ONLYDIR);
foreach($items as $item) {
echo "$item\n ";
}
?>
他按字母排序,我想按数字排序
如果我有名为 1 , 3 , 5 , 10 的子目录
会这样排列:10,1,3,5
我希望他们像这样 1、3、5、10
有选择吗?谢谢
编辑: 现在我找到了 natsort($files); 当我使用它时:
$items = array_slice(glob('albums/*', GLOB_ONLYDIR), 0, 4);
natsort($items);
我的文件夹是 995-1000 它给了我这个数组:995、996、997、1000
【问题讨论】:
-
你试过 sort() php.net/manual/en/function.sort.php
-
我不知道这会带来什么,但你试过 GLOB_NOSORT 吗?