当前位置:Gxlcms > PHP教程 > thinkphp中for循环与switch的用法详解

thinkphp中for循环与switch的用法详解

时间:2021-07-01 10:21:17 帮助过:2人阅读

1.for用法

  1. <for start="开始值" end="结束值" comparison="" step="步进值" name="循环变量名" >
  2. </for>

案例

  1. <for start="1" end="100">
  2. {$i}
  3. </for>

解析为

  1. for ($i=1;$i<100;$i+=1){
  2. echo $i;
  3. }

2.switch用法

  1. <switch name="变量" >
  2. <case value="值1" break="0或1">
输出内容1</case> <case value="值2">输出内容2</case> <default />默认情况 </switch>

案例

  1. <switch name="User.level">
  2. <case value="1">value1</case>
  3. <case value="2">value2</case>
  4. <default />default
  5. </switch>

也可以对case的value属性使用变量,例如:

  1. <switch name="User.userId">
  2. <case value="$adminId">admin</case>
  3. <case value="$memberId">member</case>
  4. <default />default
  5. </switch>

综合案例

  1. <for start="0" end="$credit['num']">
  2. <switch name="credit['level']">
  3. <case value="1"><img src="{sh::PUB}img/credit/level-heart2.png" class="star"></case>
  4. <case value="2"><img src="{sh::PUB}img/credit/level-diamond2.png" class="star"></case>
  5. <case value="3"><img src="{sh::PUB}img/credit/level-crown2.png" class="star"></case>
  6. <case value="4"><img src="{sh::PUB}img/credit/level-super-crown2.png" class="star"></case>
  7. <default />default
  8. </switch>
  9. </for>

以上就是thinkphp中for循环与switch的用法详解的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行