基本上我有一组对象值我想在 2 个单独的 html 列表中呈现
我认为最简单的方法是只在一个列表中显示偶数,而只在另一个列表中显示奇数
这是显示单个列表的当前代码
<ul>
<?php foreach ($values as $value) : ?>
<li><?php echo $value->value; ?></li>
<?php endforeach; ?>
</ul>
Run Code Online (Sandbox Code Playgroud)
尝试这个:
<ul>
<?php
/* read the index key */
foreach ($values as $key => $value) :
/* skip the current element if it doesn't have an even index */
if($key % 2 == 1) continue;
?>
<li><?php echo $value->value; ?></li>
<?php endforeach; ?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3232 次 |
| 最近记录: |