• 技术文章 >后端开发 >php教程

    smarty四则运算里面如何用小括号

    2016-06-13 10:19:03原创597
    smarty四则运算里面怎么用小括号?
    PHP code
    assign("a",$a);$smarty->assign("b",$b);$smarty->assign("c",$c);$smarty->display("t.tpl");?>


    HTML code
    a+b:<{$a+$b}>
    a/c:<{$a/$c|string_format:"%.2f"}>
    (a+b)/c:<{($a+$b)/$c|string_format:"%.2f"}>


    以上是程序和模板。
    要怎么做才可以实现(a+b)/c?

    ------解决方案--------------------
    你应该尽量在php中运算。再assign给模板。

    另外。你的代码有什么错?
    ------解决方案--------------------
    提示什么错误? php完全可以把各结果得到了再传给smarty。不就是多几个变量或是数组的问题。
    ------解决方案--------------------
    看看这篇博文
    ------解决方案--------------------
    加括号把,由于没有smarty环境。测试不了。看其他朋友怎么说。
    ------解决方案--------------------
    smarty中的四则运算
    已有 567 次阅读2006-12-4 11:14 |个人分类:PHP
    0
    {* $height=4, $width=5 *}
    {math equation="x + y" x=$height y=$width}
    OUTPUT:
    9
    {* $row_height = 10, $row_width = 20, #col_div# = 2, assigned in template *}
    {math equation="height * width / division"
    height=$row_height
    width=$row_width
    division=#col_div#}
    OUTPUT:
    100
    {* you can use parenthesis *}
    {math equation="(( x + y ) / z )" x=2 y=10 z=2}
    OUTPUT:
    6
    {* you can supply a format parameter in sprintf format *}
    {math equation="x + y" x=4.4444 y=5.0000 format="%.2f"}
    OUTPUT:
    9.44
    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:quot smarty height width format
    上一篇:phpexcel的getSheet(i)只能读取一页,如何获取一个excel有多少分页 下一篇:安装小米模板
    VIP课程(WEB全栈开发)

    相关文章推荐

    • 【腾讯云】年中优惠,「专享618元」优惠券!• 用PHP来统计在线人数的四个方法详解• 装配mysql出错Can't connect to MySQL server on 'localhost' (10061 • 求伪静态的 PHP 程序解决办法! • 关于异常类型 404 • 网址传值,该如何解决
    1/1

    PHP中文网