我的代码,以便所有文件和文件夹:列表使用PHP
<?php
$dirs = array_filter(glob('*'), 'is_dir');
$files = array_filter(glob('*'), 'is_file');
$all = $dirs + $files;
foreach ($all as $value){
echo '<li><a href="'.$value.'">'.$value.'</a></li>';
}
?>
这会将所有文件和文件夹,但按随机顺序:
Array
(
[2] => New folder
[6] => dir
[7] => dir1
[8] => dir2
[9] => dir3
[0] => A_test.txt
[1] => Index.php
[3] => app.exe
[4] => b_test
[5] => delete.php
[10] => hello.png
[11] => z_test.txt
)
sort()
不起作用。我想按默认顺序对它们进行排序。
那么,你想要做什么“订单”?你想排序吗?如果是这样,有许多排序的函数,如'sort()' –
为什么你不能只用'$ all = glob('*');'或者我在这里丢失了什么? – cmorrissey