The IF tag of ThinkPHP can beUsed to define complex condition judgmentsFor example:
<if condition="($name eq 1) OR ($name gt 100) "> value1<elseif condition="$name eq 2" />value2<else /> value3</if>
Note: The condition attribute supports eq and other judgment expressions. Comparison labels are the same as above, but they do not support the use of symbols such as ">" and "<", because template Parsing is obfuscated, so the following usage is incorrect:
<if condition="$id < 5 "> value1<else /> value2</if>
Must be changed:
<if condition="$id lt 5 "> value1<else /> value2</if>
In addition, wePhp code can be used in the condition attributeFor example:
<if condition="strtoupper($user['name']) neq 'THINKPHP' "> ThinkPHP<else /> other Framework</if>
The condition attribute supports dot syntax and object syntax, for example, automatically determining whether the user variable is an array or an object:
<if condition="$user.name neq 'ThinkPHP' "> ThinkPHP<else /> other Framework</if>
Or you know that the user variable is an object.
<if condition="$user:name neq 'ThinkPHP' "> ThinkPHP<else /> other Framework</if>
Note:Because the condition attribute of the if tag basically uses the php syntax, it is more concise to use the judgment tag and Switch tag. In principle, if you can use the switch or comparison label, try not to use the if label. Because switch and comparison labels can use variable regulators and system variables. IF the IF tag still cannot meet the requirements under some special requirements, you can use native php code or PHP label to directly write the code..