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 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据