PHP在Foreach循环中使用不同的数组?
|
我希望每个项目都有一个幻灯片。
它仅与第一个一起使用,而其他则不起作用。
知道我在做什么错吗?
我的代码:
<?php
// check $items variable exists and is not empty
if(isset($items) && !empty($items)) :
// init item count
$count = 1;
?>
<div class=\"shelf\">
<?php foreach($items as $key=>$item): ?>
<?php
// calculate if this item is the last on the shelf
// if item number can be divided by 5 with no remainders
$last_item = ( (($count) % 5 == 0)? \'item-last\' : \'\' );
?>
<div class=\"item <?php echo $last_item; ?>\">
<a href=\"/items/view/<?php echo $item[\'Item\'][\'slug\']; ?>\">
<p><?php echo $item[\'Item\'][\'name\'] ?></p>
<div id=\"CustomSlideshow\">
<?php
if ($item[\'Item\'][\'vidsite\'] = \'Pornhub\') {
for($i=1;$i<=16;$i++) {
$array[] = str_replace(\'.jpg\',sprintf(\"%01d\",$i).\'.jpg\',$item[\'Item\'][\'vidimgdir\']);
} ?>
<img src=\"<?php echo($array[0]); ?>\"/>
<img src=\"<?php echo($array[1]); ?>\"/>
<img src=\"<?php echo($array[2]); ?>\"/>
<img src=\"<?php echo($array[3]); ?>\"/>
<img src=\"<?php echo($array[4]); ?>\"/>
<img src=\"<?php echo($array[5]); ?>\"/>
<img src=\"<?php echo($array[6]); ?>\"/>
<img src=\"<?php echo($array[7]); ?>\"/>
<img src=\"<?php echo($array[8]); ?>\"/>
<img src=\"<?php echo($array[9]); ?>\"/>
<img src=\"<?php echo($array[10]); ?>\"/>
<img src=\"<?php echo($array[11]); ?>\"/>
<img src=\"<?php echo($array[12]); ?>\"/>
<img src=\"<?php echo($array[13]); ?>\"/>
<img src=\"<?php echo($array[14]); ?>\"/>
<img src=\"<?php echo($array[15]); ?>\"/>
<?php
$array=array();
} ?>
</div>
</a>
</div>
<?php
// if this is the last item, close the shelf div and create a new one
if(!empty($last_item)) {
echo \'<div class=\"clear\"></div>\';
echo \'</div>\';
echo \'<div class=\"shelf\">\';
}
?>
<?php $count++; ?>
<?php endforeach; ?>
没有找到相关结果
已邀请:
1 个回复
苛肠倒俱
我的猜测是您忘记了一个等号,因此您的代码不断为
分配相同的值。 一个等号(
)将值分配给该项,两个(equality4ѭ)比较操作数,因此应将
替换为
。 也许您已经知道这一点,并且刚刚打错了它。别担心,我也曾经犯过这个错误。 ;) 顺便说一句-如果我是你,我将替换以下代码:
与此:
矮得多。