这是由于你的洗牌。你正在随机化你的数组。让我向您介绍: http: //php.net/manual/en/function.array-reverse.php 这是
<?php
$dirname = "images";
$images = scandir($dirname);
$images = arsort(array_reverse($images, true));
$ignore = Array(".", "..");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
echo "<img src=\"". $dirname . '/' . $curimg ."\">" ;
}
}
?>
更新:
$dirname = "Images";
$images = scandir($dirname);
sort($images,SORT_NUMERIC);
krsort($images);
$ignore = Array(".", "..");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
echo "<img src=\"". $dirname . '/' . $curimg ."\"> \n" ;
}
}
我一直在使用的东西:
没有sort();
andkrsort();
我返回:
<img src="Images/1.png">
<img src="Images/10.png">
<img src="Images/11.png">
<img src="Images/2.png">
<img src="Images/3.png">
<img src="Images/4.png">
<img src="Images/5.png">
<img src="Images/6.png">
<img src="Images/7.png">
<img src="Images/8.png">
<img src="Images/9.png">
使用 krsort 和 sort.. 我返回:
<img src="Images/11.png">
<img src="Images/10.png">
<img src="Images/9.png">
<img src="Images/8.png">
<img src="Images/7.png">
<img src="Images/6.png">
<img src="Images/5.png">
<img src="Images/4.png">
<img src="Images/3.png">
<img src="Images/2.png">
<img src="Images/1.png">
我想这就是你要找的。