Home > Article > Backend Development > php Smarty character comparison code_PHP tutorial
eq is equal,
ne and neq are not equal,
gt is greater than,
lt is less than,
gte and ge are greater than or equal to,
lte and le are less than or equal to,
not is not, mod is found mold.
is [not] whether div by is divisible by a certain number,
is [not] even whether it is an even number,
$a is [not] even by $b, that is ($a / $b) % 2 == 0,
is [not] odd whether it is odd,
$a is not odd by $b, that is ($a / $b) % 2 != 0 Example:
equal/ not equal / greater than/ less than/ less than or equal/ great than or equal/ Needless to say the following
The if statement in Smarty is as flexible and easy to use as the if statement in PHP, and has added several features to suit Template engine. if must appear in pairs with /if. Else and elseif clauses can be used. The following conditional modifiers can be used: 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, ==, !=, >, <, <=, >=. These modifiers must be used with variables Or constants are separated by spaces.
Example 7-11. if statements
Example 7-11. if statement demonstration
{if $name eq "Fred"}
Welcome Sir.
{elseif $name eq "Wilma"}
Welcome Ma'am.
{else}
Welcome, whatever you are.
{/if}
{* an example with "or" logic *}
{if $name eq "Fred" or $name eq "Wilma"}
...
{/if}
{ * same as above *}
{if $name == "Fred" || $name == "Wilma"}
...
{/if}
{* the following syntax will NOT work, conditional qualifiers
must be separated from surrounding elements by spaces *}
{if $name=="Fred" || $name=="Wilma"}
...
{/if}
{* parenthesis are allowed *}
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
...
{/if}
{* you can also embed php function calls *}
{if count($var) gt 0}
...
{/if}
{* test if values are even or odd *}
{if $var is even}
...
{/if}
{ if $var is odd}
...
{/if}
{if $var is not odd}
...
{/if}
{ * test if var is divisible by 4 *}
{if $var is div by 4}
...
{/if}
{* test if var is even, grouped by two. i.e.,
0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *}
{if $var is even by 2}
...
{/if}
{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *}
{if $var is even by 3}
...
{/if}