PHP循环帮助添加非循环数据
我有一个PHP可以循环浏览我的畅销书,但是我需要以某种模式添加一些销售点,我不知道如何做到这一点 我需要做以下工作:PHP循环帮助添加非循环数据,php,loops,foreach,Php,Loops,Foreach,我有一个PHP可以循环浏览我的畅销书,但是我需要以某种模式添加一些销售点,我不知道如何做到这一点 我需要做以下工作: Product Product POS POS Product Product 我怎样才能做到这一点?现在这是我的PHP循环 <?php foreach ($featured as $product) : ?> <?php if(isset($product->productId)) : ?> <li>
Product
Product
POS
POS
Product
Product
我怎样才能做到这一点?现在这是我的PHP循环
<?php foreach ($featured as $product) : ?>
<?php if(isset($product->productId)) : ?>
<li>
<h3><strong>Best Seller</strong> <a href="#" title="View Dining"><?php echo $product->rangeTitle; ?></a></h3>
<a class="catJump" title="View Dining" href="#">View Dining</a>
<a class="pImageLink" title="Buy the Bistro Chair" href="#"><img width="242" height="130" title="6 Seater Cube Set" alt="6 Seater Cube Set" src="/assets/img/temp/bestseller.jpg" /></a>
<span class="bestSale">
<h4>6 Seater Cube Set<br /><em>was <strike>£3995</strike> NOW £2995</em></h4>
<a class="quickview" href="#" title="View Details"><strong>SAVE 10%</strong> Click here</a>
</span>
</li>
<?php endif; ?>
<?php endforeach; ?>
畅销书
6座立方体套装
为英镑;3995英镑;2995
我让你用你想要的替换
echo
语句我不知道你在这里尝试什么。显然,你需要一个条件,在这个条件下你将显示“非循环”数据。请提供它。所以你需要外部或内部循环??你想做什么???为什么你使用这样的旧模式:
和end
使用{
,无循环数据从何而来?
<?php
$i = 0;
$j = 0;
$product_count = count($featured);
while ($j<$product_count) {
if ($i==2 || $i==3) {
echo "POS";
} else {
echo $featured[$j]->productId;
++$j;
}
++$i;
if ($i>3) $i = 0;
}
?>