制作 3 列,最后一类循环

发布于 2024-10-07 11:42:10 字数 488 浏览 0 评论 0原文

我想制作 3 列并将 last 类添加到第三列。我尝试了这段代码:

<?php for ($i = 0; $i < 9; $i = $i + 4) { //can't touch this line ?>
<?php for ($j = $i; $j < ($i + 4); $j++) { //can't touch this line ?>

<?php $counter=0; ?>
            <div class="span-5<?php if ($counter % 3 == 0) { echo " last"; } ?>">
Info    
            </div>              


<?php } ?>
<?php } ?>

但没有帮助。 (它将 last 类分配给第二列)

I want to make a 3 columns and add last class to third column. I tried this code:

<?php for ($i = 0; $i < 9; $i = $i + 4) { //can't touch this line ?>
<?php for ($j = $i; $j < ($i + 4); $j++) { //can't touch this line ?>

<?php $counter=0; ?>
            <div class="span-5<?php if ($counter % 3 == 0) { echo " last"; } ?>">
Info    
            </div>              


<?php } ?>
<?php } ?>

but it doesn't help. (it assigns last class to second column)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只是我以为 2024-10-14 11:42:11

在适当的时候添加一个$counter++,它就会起作用。

<?php for ($i = 0; $i < 9; $i = $i + 4) { //can't touch this line ?>
<?php for ($j = $i; $j < ($i + 4); $j++) { //can't touch this line ?>

<?php $counter=0; ?>
            <div class="span-5<?php $counter++; if ($counter % 3 == 0) { echo " last"; } ?>">
Info    
            </div>              


<?php } ?>
<?php } ?>

Add a $counter++ at the right time and it will work.

<?php for ($i = 0; $i < 9; $i = $i + 4) { //can't touch this line ?>
<?php for ($j = $i; $j < ($i + 4); $j++) { //can't touch this line ?>

<?php $counter=0; ?>
            <div class="span-5<?php $counter++; if ($counter % 3 == 0) { echo " last"; } ?>">
Info    
            </div>              


<?php } ?>
<?php } ?>
旧城烟雨 2024-10-14 11:42:11

试试这个。它可能对你有帮助。

 <?php for ($i = 0; $i < 9; $i = $i + 4) { //can't touch this line ?>
    <?php for ($j = $i; $j < ($i + 4); $j++) { //can't touch this line ?>

    <?php if($j == 3){
         $class = 'class="last"';
     }else{
         $class = '';
     } ?>
                <div <?php $class; ?>>
    Info    
                </div>    




<?php } ?>
<?php } ?>

谢谢。

try this.it may help you.

 <?php for ($i = 0; $i < 9; $i = $i + 4) { //can't touch this line ?>
    <?php for ($j = $i; $j < ($i + 4); $j++) { //can't touch this line ?>

    <?php if($j == 3){
         $class = 'class="last"';
     }else{
         $class = '';
     } ?>
                <div <?php $class; ?>>
    Info    
                </div>    




<?php } ?>
<?php } ?>

Thanks.

喜爱纠缠 2024-10-14 11:42:11

或者只需将您的 $counter 设置为 $j+1

Or just set your $counter to $j+1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文