ThinkPHP的IF标签可以用来定义复杂的条件判断,例如:
<if condition="($name eq 1) OR ($name gt 100) "> value1 <elseif condition="$name eq 2" />value2 <else /> value3 </if>
注意:在condition属性中可以支持eq等判断表达式 ,同上面的比较标签,但是不支持带有”>”、”,所以下面的用法是错误的:
<if condition="$id < 5 "> value1 <else /> value2 </if>
必须改成:
<if condition="$id lt 5 "> value1 <else /> value2 </if>
除此之外,我们可以在condition属性里面使用php代码,例如:
<if condition="strtoupper($user['name']) neq 'THINKPHP' "> ThinkPHP <else /> other Framework </if>
condition属性可以支持点语法和对象语法,例如自动判断user变量是数组还是对象:
<if condition="$user.name neq 'ThinkPHP' "> ThinkPHP <else /> other Framework </if>
或者知道user变量是对象
<if condition="$user:name neq 'ThinkPHP' "> ThinkPHP <else /> other Framework </if>
注意:由于if标签的condition属性里面基本上使用的是php语法,尽可能使用判断标签和Switch标签会更加简洁,原则上来说,能够用switch和比较标签解决的尽量不用if标签完成。因为switch和比较标签可以使用变量调节器和系统变量。如果某些特殊的要求下面,IF标签仍然无法满足要求的话,可以使用原生php代码或者PHP标签来直接书写代码。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.