math function

Any numeric type variable can be used in the expression, and the result is output at the position of the math tag.

The variables used in the expression are passed to the function as parameters , can be a template variable or a static value.

The currently available operators are: , -, /, *, abs, ceil, cos, exp, floor, log, log10, max, min, pi, pow, rand, round, sin, sqrt, srans and tan.

If the special attribute "assign" is specified, the output value of the function will be assigned to the template specified by assign Variables instead of direct output.

Technical points: Due to the use of PHP's eval() function, the execution efficiency of the math function is not high. In PHP It will be more efficient to do mathematical operations in PHP, so do mathematical operations in PHP as much as possible and assign the results to template variables. Similar to section loops, you should explicitly avoid calling math repeatedly. Function.

eg:

{* $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


Continuing Learning
||
<?php echo "math函数";
submitReset Code