1

我使用它来显示从我的 cms 调用的缩略图列表:

<?php if($gallery_images) { ?>
<?php
$slide_page = 1;
foreach($gallery_images as $count => $image) { ?>
<li><a href="<?php echo $image->getResizedImage(); ?>" rel="example1"  title="********"><img width="125" height="80" src="<?php echo $image->getThumbnailImage()     
?>" /></a></li>

     <?php if(($count+1) % 3 == 0) {
     $slide_page += 1;
      ?>

它从我的 CMS 中调用图像并以 3 个一组的形式显示它们,并添加了一些 jquery 来滚动浏览这些集合。

我想要做的是将它与我​​的视频合并到同一个列表中。

视频代码如下:

<?php foreach($videos as $count => $video) { ?>
<a href="<?php echo $video->getLocation(); ?>" class="videolink"><img src="{thumbnail}" />Video A</a>
<?php } ?> 

我试过使用 array_merge 函数,但似乎有困难,任何帮助将不胜感激

4

1 回答 1

1

这很简单:

foreach (array_merge($gallery_images, $videos) as $count => $value) { }

你可能还想看看array_chunk()


更新:

<? foreach (array_merge($images, $videos) as $key => $value): ?>
    <? if (is_object($value) === true): ?>
        <? if (method_exists($value, 'getLocation') === true): ?>
            <a href="<?= $video->getLocation(); ?>" class="videolink"><img src="{thumbnail}" />Video A</a>
        <? elseif (method_exists($value, 'getResizedImage') === true): ?>
            <a href="<?= $image->getResizedImage(); ?>" rel="example1"  title="***"><img width="125" height="80" src="<?= $image->getThumbnailImage(); ?>" /></a>
        <? endif; ?>
    <? endif; ?>
<? endforeach; ?>
于 2011-01-19T17:11:10.590 回答