用于fotorama的Foreach循环

时间:2015-08-27 23:25:39

标签: php loops foreach fotorama

我试图使用插件fotorama的foreach循环。

我想要做的是为主图库图片加载一个半尺寸的图像。我在foreach工作,但我想使用完整图像的数据完整标签,但我不能让它工作。

这是工作代码。

<div class="fotorama"
                 data-allowfullscreen="native"
                 data-nav="thumbs"
                 data-fit="scaledown"
                 data-width="100%"
                 data-height="100%"
                 data-arrows="true"
                 data-click="true"
                 data-swipe="true">
                <?php
                      $dirname = "admin/image-upload/uploads/";
                      $images = glob($dirname."*.*");
                      foreach($images as $image) {
                      echo '<img src="'.$image.'" /><br />';
                      }
                ?>
            </div>

这就是我想要做的事情。

<div class="fotorama"
                 data-allowfullscreen="native"
                 data-nav="thumbs"
                 data-fit="scaledown"
                 data-width="100%"
                 data-height="100%"
                 data-arrows="true"
                 data-click="true"
                 data-swipe="true">
                <?php
                      $dirname = "admin/image-upload/uploads/";
                      $images = glob($dirname."*.*");
                      $dirname2 = "admin/image-upload/full/";
                      $images2 = glob($dirname2."*.*");
                      $fullImgs = "<img data-full=".$image2." src=".$image." /><br />";
                      foreach($fullImgs as $fullImg) {
                      echo $fullImg;
                      }
                ?>


            </div>

感谢高级人员

2 个答案:

答案 0 :(得分:0)

试试这个:

$dirname = "admin/image-upload/uploads/";
$images = glob($dirname."*.*");
$dirname2 = "admin/image-upload/full/";
$images2 = glob($dirname2."*.*");
$array = array_merge($images, $images2);

// Supossing both array have same length
$length = count($images);
for($i = 0; $j = $length; $i < $length; $i++, $j++) {
    echo '<img data-full=".$images2[$j]." src=".$images[$i]." /><br />';
}

答案 1 :(得分:0)

我认为你想要的是:

<?php
  $dirname = "admin/image-upload/uploads/";
  $images = glob($dirname."*.*");
  $dirname2 = "admin/image-upload/full/";
  $images2 = glob($dirname2."*.*");
  //assuming $images and $images2 are the same length...
  foreach ($images as $k => $v) {
    echo "<img data-full=".$images2[$k]." src=".$v." /><br />";
  }
?>

没有经过测试,但应该提出想法......