The switch label in the ThinkPHP template is used to output different values in the template according to different situations.
The ThinkPHP template engine supports switch judgment and outputs different results based on different conditions. The format is as follows:
<Switch name = "variable name"> <case value = "value 1"> output content 1 </case> <case value = "value 2"> output content 2 </case> <default/> default </switch>
Examples:
<Switch name = "uid"> <case value = "1"> administrator </case> <default/> visitor </switch>
Note:
The name attribute can use functions and system variables. The attribute value is the variable name without the $ symbol, and the value must contain the $ symbol when using the variable, as shown in the preceding example.
The value of value does not support simultaneous judgment of multiple conditions when the variable method is used, as shown in the following multi-condition judgment.
Multi-condition judgment:
The value Attribute of case can support simultaneous judgment of multiple conditions. Use the | symbol for segmentation:
<Switch name = "Think. get. type "> <case value =" gif | png | jpeg "> Image Format File </case> <default/> other format files </switch>
This indicates that if $ _ GET ["type"] is set to gif, png, or jpg, the image format is used.
The name attribute can also be a system variable and a function can be used.Such:
<Switch name = "Think. get. username | function1"> ...... </switch>