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

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

    报告相同问题?

    悬赏问题

    • ¥30 android百度地图SDK海量点显示标题
    • ¥15 windows导入environment.yml运行conda env create -f environment_win.yml命令报错
    • ¥15 这段代码可以正常运行,打包后无法执行,在执行for内容之前一直不断弹窗,请修改调整
    • ¥15 C语言判断有向图是否存在环路
    • ¥15 请问4.11到4.18以及4.27和4.29公式的具体推导过程是怎样的呢
    • ¥20 将resnet50中的卷积替换微ODConv动态卷积
    • ¥15 通过文本框输入商品信息点击按钮将商品信息列举出来点击加入购物车商品信息添加到表单中
    • ¥100 这是什么压缩算法?如何解压?
    • ¥20 upload上传实验报错500,如何解决?(操作系统-windows)
    • ¥15 谁知道 ShaderGraph 那个节点可以接入 Particle System -> Custom Data