Home Backend Development PHP Tutorial Detailed explanation of the usage of for loop and switch statement in thinkPHP template

Detailed explanation of the usage of for loop and switch statement in thinkPHP template

May 30, 2018 am 09:55 AM
php switch thinkphp

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>
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



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

PHP implements the method of obtaining the current date and the day of the month this Monday is


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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles