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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵