这是php for循环的开始。我想对其进行编辑,以便将“在此处插入数字”替换为递增的数字。即。第一个循环是1,然后是2,然后是3,依此类推。
<?php foreach ($_productCollection as $_product): ?>
<div style="float: left; font-size: 120px;height:50px;padding-top:50px; color:#ccc">INSERT NUMBER HERE</div>
<div class="listing-item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">我如何才能做到这一点?
谢谢
发布于 2010-01-01 23:51:44
<?php
$n = 0;
foreach ($_productCollection as $_product):
$n++;
?>
<div style="float: left; font-size: 120px;height:50px;padding-top:50px; color:#ccc"><?php echo $n; ?>
</div>
<div class="listing-item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">发布于 2010-01-01 23:57:43
您可以使用array_keys()从关联数组中获取索引数组,此时foreach将把索引作为新的键,将旧的键作为新值。用新值索引旧数组将得到旧值,而新键将是数组中元素的计数器。
https://stackoverflow.com/questions/1988902
复制相似问题