输出文件夹中的图像,并在PHP循环中每返回6次后清除浮点值

输出文件夹中的图像,并在PHP循环中每返回6次后清除浮点值,php,for-loop,Php,For Loop,我正在尝试计算文件夹中的图像,并希望在从文件夹返回每6个图像后清除浮动。这是我到目前为止得到的代码,但它吐出的清白比我想要的要多。有人能帮我找到一个解决办法吗?提前谢谢。下面是我的代码 <?php $i = 0; $dirname = "images"; $images = scandir($dirname); $filecount = count(glob("images/". "*.png")); //echo $filecount; $ignore = Array(".", "

我正在尝试计算文件夹中的图像,并希望在从文件夹返回每6个图像后清除浮动。这是我到目前为止得到的代码,但它吐出的清白比我想要的要多。有人能帮我找到一个解决办法吗?提前谢谢。下面是我的代码

<?php
$i = 0;
$dirname = "images"; 
$images = scandir($dirname);
$filecount = count(glob("images/". "*.png"));
 //echo $filecount;

$ignore = Array(".", "..", "otherfiletoignore");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {

if ($i % 6 === 0){

echo "<div style='clear:both;></div>'";

}

echo "<div style='float:left;'><img src='images/",$curimg."'"," /></div>";

}
}

?>

您永远不会更改
$i
的值,因此每次通过循环时它都将为零。在这种情况下,您希望使用
for
循环,而不是
foreach
循环

$images = glob("images/*.png");
$filecount = count($images);
$ignore = Array(".", "..", "otherfiletoignore");
for ($i = 0; $i < $filecount; $i++){
    if(!in_array($images[$i], $ignore)) {
        if ($i % 6 === 0){
                echo "<div style='clear:both;></div>'";
        }
        echo "<div style='float:left;'><img src='images/",$images[$i]."'"," /></div>";
    }
}
$images=glob(“images/*.png”);
$filecount=count($images);
$ignore=Array(“.”、“.”、“.otherfiletoignore”);
对于($i=0;$i<$filecount;$i++){
如果(!in_数组($images[$i],$ignore)){
如果($i%6==0){

echo“此代码将吐出行
echo”它在每个图像之前和之后吐出清除div。我正在尝试在文件夹中每6个图像之后清除div。我希望这有意义。谢谢。
if(!in_array($curimg, $ignore)) {

if ($i % 6 === 0){
if(!in_array($curimg, $ignore)) {
$i++;
if ($i % 6 === 0){