我试图在PHP中创建一个循环,在这个循环中,购物车中的每一个额外项目,送货都会得到10%的折扣。
--这是我想要的结果:
等。
我现在不知道该把我的$quantity变量放在哪里。
My:
<?php
$quantity = 10;
$shipping = 30;
for( $discount = 0.5; $discount >= 0.1; $discount - 0.1 ) {
$shipping = $shipping + ( $shipping * $discount );
}
echo $shipping;
?>发布于 2015-11-19 13:01:31
您应该迭代数量值,而不是折扣。
$shippingDefault = 30;
$discount = 0.5;
for ($i = 2 ; $i <= $quantity; $i++) {
if ($discount < 0.1) {
$discount = 0.1;
}
$shipping += ( $shippingDefault * $discount );
$discount -= 0.1;
}https://stackoverflow.com/questions/33804491
复制相似问题