Home >Backend Development >PHP Tutorial >PHP template engine smarty generates random numbers Usage of math function in smarty
? Isn’t it very simple? In fact, the math function in the smarty template is mainly used here. Here is a brief explanation of the function and usage of the Smarty math function. math allows template designers to perform mathematical expression operations in templates. Variables of any numeric type can be used in expressions, and the results are output in the position of the math tag. Variables used in expressions are passed as parameters to functions, which can be templates Variable or static value. Currently available operators are: +, -, /, *, abs, ceil, cos, exp, floor, log, log10, max, min, pi, pow, rand, round, sin, sqrt , srans and tan . For more information on math functions, check out the PHP documentation. If the special attribute "assign" is specified, the output value of the function will be assigned to the template variable specified by assign instead of being output directly. However, it should be noted that: due to the use of PHP's eval() function, the execution efficiency of the math function is not high. It is more efficient to perform mathematical operations in PHP, so it is necessary to perform mathematical operations in PHP as much as possible and assign the results to to template variables. Second, smart math function demonstration Example 1:
Output result: 9 Example 2:
Output result: 100 Example 3:
Output result: 6 Example 4:
Output result: 9.44 |