开发者

Using Array_merge for 2 for_each arrays

开发者 https://www.devze.com 2023-02-05 19:13 出处:网络
Im using this to display a list of thumnails called from my cms: <?php if($gallery_images) { ?> <?php

Im using this to display a list of thumnails called from my 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->getThumbnai开发者_运维技巧lImage()     
?>" /></a></li>

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

It calls images from within my CMS and displays them in groups of 3, with some added jquery to scroll through the sets.

What im trying to do is merge this with my videos within the same list.

The video code is as follows:

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

Ive tried using the array_merge function but seem to be having difficulties any help would be greatly appreciated


It's easy:

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

You may also want to look at array_chunk().


Update:

<? 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; ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消