Home > Article > Backend Development > ThinkPHP template range judgment output In tag and Range tag usage
This article mainly introduces the usage of the In tag and the Range tag of the ThinkPHP template range judgment output. Friends who need it can refer to the
The in tag and range tag of the ThinkPHP template are used tojudge a certain template. Whether the variable is within a certain range.
1.in tag
ThinkPHP’s in tag is used to determine whether a template variable is within a certain range. The format is as follows:
<in name="变量名" value="值1,值2,...">要输出的内容</in>
When used, in the module Set variables in operations (such as Index/display) and assign values to the template:
$groupId = 1; $this->assign( "groupId", $groupId );
Template/Tpl/default/Index/display.html, use the in tag as follows:
<in name="groupId" value="1,2,3">管理群组</in>
Run the Example, can output:
Management Group
The php code of this example is equivalent to:
<?php if(in_array(($groupId), explode(',',"1,2,3"))){ echo '管理群组'; } ?>
Note: The value of the variable can also be a string or array , the value of the value attribute can use variables.
2.notin tag
There is also a notin tag corresponding to the in tag, which means it is judged not to be within a certain range:
Usage such as:
<notin name="groupId" value="1,2,3">非管理群组</notin>
The above two tag examples combined are equivalent to:
<in name="groupId" value="1,2,3">管理群组<else />非管理群组</in>
3.range tag
ThinkPHP’s in and notin tags can also be used range tag instead, such as:
<range name="groupId" value="1,2,3" type="in" >管理群组</range>
The above example is equivalent to the in tag. When the value of the type attribute is notin, it is equivalent to the notin tag.
Related recommendations:
How to use thinkPHP’s Html template tag
ThinkPHP template judgment output Empty tag usage
The above is the detailed content of ThinkPHP template range judgment output In tag and Range tag usage. For more information, please follow other related articles on the PHP Chinese website!