Usage example of for loop and switch statement in thinkPHP template_php example

WBOY
Release: 2023-03-03 07:08:02
Original
1135 people have browsed it

The example in this article describes the usage of for loop and switch statement in thinkPHP template. Share it with everyone for your reference, the details are as follows:

1.for usage

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

Copy after login

Case

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

Copy after login

resolves to

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

Copy after login

2.switch usage

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

Copy after login

Case

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

Copy after login

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>

Copy after login

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>

Copy after login

Readers who are interested in more thinkPHP-related content can check out the special topics on this site: "Introduction to ThinkPHP Tutorial", "Summary of thinkPHP Template Operation Skills", "Summary of Common Methods of ThinkPHP", "Introduction to Codeigniter Tutorial", "CI (CodeIgniter) Framework" "Advanced Tutorial", "Introduction Tutorial on Zend FrameWork Framework", "Basic Tutorial on Smarty Template" and "Summary of PHP Template Technology".

I hope that what is described in this article will be helpful to everyone’s PHP program design based on the ThinkPHP framework.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template