1. 程式人生 > >PHP 模板 smarty 邏輯運算子號

PHP 模板 smarty 邏輯運算子號

新進個公司,網站比較老, 用到了smarty ,,  所以總結一下smarty 裡面的邏輯運算子

eq    equal : 相等
neq    not equal:不等於
gt    greater than:大於
lt    less than:小於
lte    less than or equal:小於等於
gte    great than or equal:大於等於
is even:  是偶數
is odd:  是奇數
is not even: 不是偶數
is not odd  不是奇數
not:   非
mod:   求模取餘
div by:  被。。。除
&&    and : 並且
||    or : 或者
is [not] div by 是否能被某數整除,例如:{if $smarty.get.age is div by 3}...{/if}
is [not] even 是否為偶數,例如:$a is [not] even by $b即($a / $b) % 2 == 0,
is [not] odd 是否為奇,例如:$a is not odd by $b即($a / $b) % 2 != 0

{if $_global_password} 是判斷變數存不存在....

{if $_global_password!==''} 是判斷變數等不等於空....

Smarty 中的 if 語句和中if 必須於 /if 成對出現. 可以使用 else 和 elseif 子句。

模板中使用 eq、ne、neq、gt、lt、lte、le、gte、ge、is even、is odd、is not even、is not odd、not、mod、div by、even by、odd by、==、!=、>、<、<=、>= 這些邏輯運算子號的時候必須和變數或常量用空格格開。