dpdbu24262 2018-08-01 15:48
浏览 71
已采纳

PHP循环基于引导列的行号

I have one design issue that I want to solve. I've spend 2 days on this and I know that its an easy one...

I want to echo the articles with this order: col-8, col-4, col-4, col-8, col-8,col-4... and so on.

enter image description here

I've made it to echo the articles like this: col-8, col-4, col-8, col-4, col-8, col-4... and so on.

if ($article->id % 2 == 0) { echo 4; } elseif ($article->id % 2 == 1) { echo 8; }

I know that I have to use the loop inside one other loop, but I am stuck.

If you have any ideas, let me know. Thank you!

</div>
  • 写回答

1条回答 默认 最新

  • duanpan3166 2018-08-01 15:53
    关注

    You need to adjust your modulus conditional to fit the loop / starting point you want.

    Give this a go:

    if ($article->id % 4 == 0 || $article->id % 4 == 1) { echo 8; } else { echo 4; }
    

    https://ideone.com/IneWWC

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?