2011-01-19 27 views
1

進出口以此來顯示從我的CMS稱爲thumnails的列表:使用Array_merge 2個的for_each陣列

<?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功能,但

我用盡似乎有困難的任何幫助,將不勝感激

+1

[`array_merge`](http://de2.php.net/manual/en/function.array-merge.php)是相當簡單的。你傳入任意數量的數組,它將返回一個合併數組。請指出你有困難的地方。 – Gordon 2011-01-19 16:56:45

回答

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

@Christian:那麼問題是什麼? – 2011-01-20 09:16:07