这是我的PHP块。
<?php
我知道这是定义数组的地方。
$string =array();
$dir = opendir($filePaththumb);
while ($file = readdir($dir)) {
if (eregi("\.png",$file) || eregi("\.jpg",$file) || eregi("\.gif",$file) ) {
$string[] = $file;
}
}
我认为我应该在代码继续这一点之前使用natsort()。
echo "<b><font size='$font_size'>".$gallery_name."</font></b><br>";
$loop = "0";
while (sizeof($string) != 0){
$img = array_pop($string);
我可以在这里使用natsort()吗?
echo "<center><a href='$filePath$img' download='$filePath$img' target='$target_thumb'><img src='$filePaththumb$img' border='0' width='100%'/><BR><IMG src='img/download.png'></a><BR><BR><BR><BR></center>";
$loop = $loop + 1;
if ($loop == $loop_end) {
echo "<br>";
$loop = "0";
}
}
?>
如何按自然顺序对图像进行排序?
答案 0 :(得分:0)
感谢大家的投入!你的建议对我帮助很大!
<?php
$string =array();
$dir = opendir($filePaththumb);
while ($file = readdir($dir)) {
if (eregi("\.png",$file) || eregi("\.jpg",$file) || eregi("\.gif",$file) ) {
$string[] = $file;
使用.jpg / .gif / .png文件填充数组后,我使用了
natsort($string);
将图片文件排列在自然顺序
我还使用array_reverse($string);
来排列图像文件的顺序,从最大自然顺序值的文件名到降序自然顺序值。
}
}
echo "<b><font size='$font_size'>".$gallery_name."</font></b><br>";
$loop = "0";
while (sizeof($string) != 0){
$img = array_pop($string);
echo "<center><a href='$filePath$img' download='$filePath$img' target='$target_thumb'><img src='$filePaththumb$img' border='0' width='100%'/><BR><IMG src='img/download.png'></a><BR><BR><BR><BR></center>";
$loop = $loop + 1;
if ($loop == $loop_end) {
echo "<br>";
$loop = "0";
}
}
?>
再次感谢大家!
答案 1 :(得分:-1)