如何用php的循环编写计算商品价格折扣并以表格显示的代码

如题所述

拆开想,

1.取到商品数组
2.用foreach进行循环
3.循环内进行每个商品折扣计算
4.把结果传到网页
5.在网页中用循环把新数组循环
例如:

<table>
    <tr>
        <td>价格</td>
        <td>折扣后价格</td>
    </tr>
    <?php foreach($goods as $k=>$v){?>
        <tr>
            <td><?php echo $v['price'];?></td>
            <td><?php echo $v['new_price'];?></td>
        </tr>
    <?php }?>
</table>

温馨提示:答案为网友推荐,仅供参考
相似回答