我会这样做 - 用 $imgDir 交换一个数组。$images 数组现在包含路径和文件名。
<?php
$imgDirs = array("im/", "out/");
$images = array();
// take one of the given directories
foreach($imgDirs as $imgDir)
{
// open a directory reader for this given directory
$dh = opendir($imgDir);
// read a single filename of this directory (stop loop if there is no more file)
while (false !== ($filename = readdir($dh)))
{
// ignore '.' and '..'
if($filename != '.' && $filename != '..')
{
// add the directory and filename to the images array
// all images, regardless of the folder, are stored in one array :)
$images[] = $imgDir . $filename;
}
}
closedir($dh);
}
natsort($images);
// loop for every image
foreach($images as $file)
{
// for every img, echo a div-img-/div-combination
echo "<div id=\"slideWrapper\">\n";
echo "<img src=\"$file\" width=\"1000\" height=\"683\" alt=\"$file\" />\n";
echo "</div>\n";
}
?>