This article mainly introduces the usage of for loop and switch statement in thinkPHP template, and analyzes the specific functions, definitions and specific usage techniques of for loop and switch statement in the form of examples. Friends in need can refer to it
1.for usage
##
<for start="开始值" end="结束值" comparison="" step="步进值" name="循环变量名" > </for>
<for start="1" end="100"> {$i} </for>
for ($i=1;$i<100;$i+=1){ echo $i; }
<switch name="变量" > <case value="值1" break="0或1">输出内容1</case> <case value="值2">输出内容2</case> <default />默认情况 </switch>
Case
<switch name="User.level"> <case value="1">value1</case> <case value="2">value2</case> <default />default </switch>
You can also use variables for the value attribute of the case, for example:
<switch name="User.userId"> <case value="$adminId">admin</case> <case value="$memberId">member</case> <default />default </switch>
Comprehensive case
<for start="0" end="$credit['num']"> <switch name="credit['level']"> <case value="1"><img src="{sh::PUB}img/credit/level-heart2.png" class="star"></case> <case value="2"><img src="{sh::PUB}img/credit/level-diamond2.png" class="star"></case> <case value="3"><img src="{sh::PUB}img/credit/level-crown2.png" class="star"></case> <case value="4"><img src="{sh::PUB}img/credit/level-super-crown2.png" class="star"></case> <default />default </switch> </for>
The above is the entire content of this article, I hope it will be helpful to everyone’s study .
Related recommendations:
php Detailed explanation of security configuration records and common errors
str_pad() function in php Detailed explanation of usage
The above is the detailed content of Detailed explanation of the usage of for loop and switch statement in thinkPHP template. For more information, please follow other related articles on the PHP Chinese website!