我想要归档的是我的类别显示折扣百分比。
<span class="box-price">
<?php if (!$product['special']) { ?>
<span class="box-price-amount"> <?php echo $product['price']; ?></span>
<?php } else { ?>
<span class="box-price-amount"> <?php echo $product['special']; ?></span>
<?php } ?>
必须对价格和特殊价格进行计算,以计算差异并以百分比显示,这是你希望能阐明的。
关于如何做到这一点,有什么想法吗?
这个公式非常简单。
(Older - Newer) / Older
例如
设Older = 100
让Newer = 75
Percentage decrease: (100 - 75) / 100
=0.25
=25%
另一个例子
让Older = 354
设Newer = 67
Percentage decrease: (354 - 67) / 354 = 0.81 (2 d.p). = 81%
更接近PHP
我没有看到你付出太多努力,所以我不会让这件事对你来说太容易。
据我所知,$product['price']
是你的长辈。
$product['special']
是您的新产品。
现在用您的变量交换Older
和Newer
,您应该有一些可以工作的PHP了。