久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      詳解在PHP模板引擎smarty生成隨機(jī)數(shù)的方法和math函數(shù)

      詳解在PHP模板引擎smarty生成隨機(jī)數(shù)的方法和math函數(shù)

      這個(gè)當(dāng)然絕對是可行的,但過于復(fù)雜,下面作者就如何直接在smarty模板中生成隨機(jī)數(shù)這個(gè)小技巧和大家分享一下。

      現(xiàn)在假設(shè)在smarty模板中需要生成一個(gè)125-324之間的隨機(jī)數(shù),那么可以按如下寫法:

      代碼如下:

      {math equation=rand(125,324)}

      這樣就實(shí)現(xiàn)了我們的目的了,怎么樣?是不是很簡單,其實(shí)這里主要用到了smarty模板中的math函數(shù),下面對Smarty math函數(shù)的作用以及用法做個(gè)簡要的講解。

      math 允許模板設(shè)計(jì)者在模板中進(jìn)行數(shù)學(xué)表達(dá)式運(yùn)算. 均表達(dá)式中可以使用任何數(shù)值類型的變量,結(jié)果在 math 標(biāo)簽的位置輸出. 表達(dá)式中使用的變量被當(dāng)做參數(shù)傳遞給函數(shù),可以是模板變量或靜態(tài)值. 目前可以使用的運(yùn)算符有:+, -, /, *, abs, ceil, cos, exp, floor, log, log10, max, min, pi, pow, rand, round, sin, sqrt, srans 和 tan .關(guān)于數(shù)學(xué)函數(shù)的詳細(xì)信息,請查看 PHP 文檔。

      如果指定了 "assign" 這個(gè)特殊屬性,該函數(shù)的輸出值將被賦給由 assign 指定的模板變量,而不是直接輸出。

      不過需要注意的是: 由于使用了 php 的 eval() 函數(shù),math 函數(shù)的執(zhí)行效率不高. 在 PHP 中做數(shù)學(xué)運(yùn)算效率會更高一些,因此要盡可能在 PHP 中做數(shù)學(xué)運(yùn)算,將結(jié)果賦給模板變量。

      smarty math 函數(shù)演示

      代碼如下:

      {* $height=4, $width=5 *} {math equation="x + y" x=$height y=$width}

      輸出結(jié)果:9

      代碼如下:

      {* $row_height = 10, $row_width = 20, #col_p# = 2, assigned in template *} {math equation="height * width / pision" height=$row_height width=$row_width pision=#col_p#}

      輸出結(jié)果:100

      代碼如下:

      {math equation="(( x + y ) / z )" x=2 y=10 z=2}

      輸出結(jié)果:6

      代碼如下:

      {* you can supply a format parameter in sprintf format *} {math equation="x + y" x=4.4444 y=5.0000 format="%.2f"}

      輸出結(jié)果:9.44

      相關(guān)學(xué)習(xí)推薦:PHP編程從入門到精通

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號