Noe*_*aba 6 math variables equation smarty
祝大家度过愉快的一天,我有事要问你好,更好地了解这里是我的代码:
{math equation=((($order_total-$commission)+$discount+$delivery_charge)*$rate)}
Run Code Online (Sandbox Code Playgroud)
我希望将其传递给另一个变量,在php中我想要像这样
<?php
$var=0
foreach($result as $resultA){
$var = $var+((($order_total-$commission)+$discount+$delivery_charge)*$rate);
}
?>
Run Code Online (Sandbox Code Playgroud)
希望你能帮助我们!
rod*_*ehm 13
如果您正在使用Smarty 3,我强烈建议放弃{math}:
{$order_total = 123}
{$commission = 13}
{$discount = 10}
{$delivery_charge = 20}
{$rate = 1.1}
{$result = 0}
{$result = $result + ($order_total - $commission + $discount + $delivery_charge) * $rate}
{$result}
Run Code Online (Sandbox Code Playgroud)
它具有更好的可读性和更快性(因为表达式实际上是编译的,而不是eval()ed一遍又一遍).
Smarty 2相当于:
{assign var="order_total" value=123}
{assign var="commission" value=13}
{assign var="discount" value=10}
{assign var="delivery_charge" value=20}
{assign var="rate" value=1.1}
{assign var="result" value=0}
{math
assign="result"
equation="result + (order_total - commission + discount + delivery_charge) * rate"
result=$result
order_total=$order_total
commission=$commission
discount=$discount
delivery_charge=$delivery_charge
rate=$rate
}
{$result}
Run Code Online (Sandbox Code Playgroud)
如果有机会升级到Smarty 3 - 那就去吧!