以自然降序对目录文件名数组进行排序 [英] Sorting an array of directory filenames in descending natural order
本文介绍了以自然降序对目录文件名数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个内容目录,以自然降序返回.
I have a content directory to be returned in descending natural order.
我正在使用scandir()
和natsort()
,但是添加array_reverse()
不会产生任何结果.
I'm using scandir()
and natsort()
, but the addition of array_reverse()
yields no results.
我一直在研究使用opendir()
和readdir()
的组合以及其他会影响此结果的东西.
I've been researching using a combination of opendir()
and readdir()
as well what ever else to affect this outcome.
要排序的项目是编号的图像文件.它们将返回为:10
9
8
7
依此类推,但类似1000
999
998
997
...直到0
The items to be sorted are numbered image files. They are to be returned as: 10
9
8
7
and so on, but like from like 1000
999
998
997
... until 0
这是我当前的代码:
$dir = 'dead_dir/dead_content/';
$launcher = scandir($dir);
natsort($launcher);
array_reverse($launcher, false);
foreach ($launcher as $value) {
if (in_array(pathinfo($value, PATHINFO_EXTENSION), array('png'))) {
echo '<img src="dead_dir/dead_content/'.$value.'" />'
}
}
推荐答案
$dir='dead_dir/dead_content/';
$launcher= scandir($dir);
natsort($launcher);
$r_launcher = array_reverse($launcher,true);
foreach($r_launcher as $value ){
if(in_array(pathinfo($value, PATHINFO_EXTENSION),array('png'))){
echo '<img src="dead_dir/dead_content/'.$value.'" />'}}
这篇关于以自然降序对目录文件名数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文