gpt4 book ai didi

math - smarty 将 {math} 方程中的值赋给一个变量

转载 作者:行者123 更新时间:2023-12-04 13:33:41 29 4
gpt4 key购买 nike

祝大家有个愉快的一天,我有话要问你,为了更好地理解这里是我的代码:

{math equation=((($order_total-$commission)+$discount+$delivery_charge)*$rate)}

我希望将其传递给另一个变量,在 php 中我想像这样
<?php 
$var=0
foreach($result as $resultA){
$var = $var+((($order_total-$commission)+$discount+$delivery_charge)*$rate);
}
?>

希望你们能帮帮我!

最佳答案

如果您使用 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}

它具有更好的可读性和更快的速度(因为表达式实际上是被编译的,而不是一次又一次地编译 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}

如果有机会升级到 Smarty 3 - 去做吧!

关于math - smarty 将 {math} 方程中的值赋给一个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11154091/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com