gpt4 book ai didi

php - PHP foreach循环中的自动递增数字

转载 作者:可可西里 更新时间:2023-10-31 23:56:36 27 4
gpt4 key购买 nike

这是 php for 循环的开始。我想对其进行编辑,以便将“在此处插入数字”替换为递增的数字。 IE。首先循环它将是 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; ?>">

我怎样才能做到这一点?

谢谢

最佳答案

<?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; ?>">

关于php - PHP foreach循环中的自动递增数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1988902/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com