Home >Backend Development >PHP Tutorial >Detailed explanation of the usage of ThinkPHP template comparison tag_PHP tutorial
ThinkPHP template engine provides a wealth of comparison tags, and their usage format is:
<比较标签 name="变量" value="值">内容</比较标签>
The comparison tags supported by the ThinkPHP system and their meanings are:
eq or equal: equal to
neq or notequal: not equal to
gt: greater than
egt: greater than or equal to
lt: less than
elt: less than or equal to
heq: constant equal to
nheq: not always equal to
1. The usage of comparison tags is basically the same, the difference lies in the different conditions for judgment .
Such as eq tag:
<eq name="name" value="value">value</eq>
means that if the value of the name variable is equal to value, it will be output.
Or it can also be written as:
<equal name="name" value="value">value</equal>
can also be mixed with else tags , such as:
<eq name="name" value="value">相等<else/>不相等</eq>
gt tag is used as follows:
<gt name="name" value="5">value</gt>
means that when the value of the name variable is greater than 5, output
Theegt tag is used as follows:
<egt name="name" value="5">value</egt>
means that when the value of the name variable is not less than 5, output
2. The variables in the comparison tag can support object attributes or arrays, or even system variables :
An example of the eq tag is as follows:
<eq name="vo.name" value="5">{$vo.name}</eq>
means that when the attribute of the vo object (or array, or automatic judgment) is equal to 5, output
<eq name="vo:name" value="5">{$vo.name}</eq>
means that when the attribute of the vo object is equal to 5, it will output
<eq name="vo['name']" value="5">{$vo.name}</eq>
means that when $vo['name'] is equal to 5, output
3. You can also use functions for variables
For example:
<eq name="vo:name|strlen" value="5">{$vo.name}</eq>
means that when the string length of the attribute value of the vo object is equal to 5,
will be output4. Variable names can support system variables , for example:
<eq name="Think.get.name" value="value">相等<else/>不相等</eq>
5. Usually the value of the comparison tag is a string or number. If you need to use a variable, you only need to add the "$" sign in front.
For example:
<eq name="vo:name" value="$a">{$vo.name}</eq>
means that when the attribute of the vo object is equal to $a, it will output
6. All comparison tags can use the compare tag (in fact, all comparison tags are aliases of the compare tag), for example:
<compare name="name" value="5" type="eq">value</compare>
means that when the value of the name variable is equal to 5, output
is equivalent to
<eq name="name" value="5" >value</eq>
The value of the type attribute is the comparison tag name listed above