The switch label in the thinkphp template is used to output different values in the template according to different conditions.
The thinkphp template engine supports switch judgment and can output different results according to different conditions, using the following format:
<switch name= "variable name" >
<case value= "value 1" > Output 1</case>
<case value= "value 2" > Output 2</case >
<default/> Default
</switch>
Examples of usage are as follows:
<switch name= "UID" >
<case value= "1" > Admin </case>
<default/> Visitor
</switch>
Note here:
The Name property can use functions as well as system variables with property values of variable names, no $ symbols, and value values that use variables with a $ symbol , as shown in the previous example.
in the case of variable mode, value values are not supported by multiple conditions , such as the following multiple conditional judgments.
Multi-Conditional judgment:
The Value property of the case can be used to support multiple conditions, using | Symbols for segmentation:
<switch name= "Think.get.type" >
<case value= "gif|png|jpeg" > Image format Files </case>
<default/ > Other format Files
</switch>
This means that if the value of the $_get["type" is GIF, PNG, or JPG, it is judged as an image format.
The Name property can also be a system variable, and you can use a function such as:
<switch name= "Think.get.username|function1" > ...
</switch>