如何在foreach循环中每5次迭代后定义html标记

如何在foreach循环中每5次迭代后定义html标记

我只想知道如何在foreach循环中每5次迭代后定义html标记

<?php
$i=1;
foreach($videoEntries as $data){
?>
    <div class="item-main">
        <div class="item">
        <a href="javascript:;" onclick="ratePopup(2)" title="<?php echo $data->video_name;?>">
        <div class="overlaid"></div>
        <img src="<?php echo $image_url;?>"  width="93" height="89"/>
        </a>
        </div>
        <p title="Trailer Name"><strong><?php echo $data->video_name;?></strong></p>
        <p title="Released Date"><?php echo $data->video_released_date;?></p>
    </div>
<?php
    if($i == 5){
        echo "<br clear = 'all'>";
    }
}
?>

所需的结果或帮助绝对得到认可
12345
<br clear="all">
678910
<br clear="all">

最佳答案

试试这个:

<?php
$i=0;
foreach($videoEntries as $data){
$i++;
?>
    <div class="item-main">
        <div class="item">
        <a href="javascript:;" onclick="ratePopup(2)" title="<?php echo $data->video_name;?>">
        <div class="overlaid"></div>
        <img src="<?php echo $image_url;?>"  width="93" height="89"/>
        </a>
        </div>
        <p title="Trailer Name"><strong><?php echo $data->video_name;?></strong></p>
        <p title="Released Date"><?php echo $data->video_released_date;?></p>
    </div>
<?php
    if($i == 5){
        echo "<br clear = 'all'>";
        $i=0;
    }
}
?>

07-24 15:18