Home  >  Article  >  php教程  >  thinkphp的if标签

thinkphp的if标签

WBOY
WBOYOriginal
2016-06-06 20:09:161518browse

使用if标签来定义复杂的条件判断。 If标签(条件判断标签) 闭合非闭合标签 属性condition(必须):要判断的条件 elseif标签(条件判断标签) 闭合闭合标签 属性condition(必须):要判断的条件 else标签(条件判断标签) 闭合闭合标签 属性无 用法示例:

使用if标签来定义复杂的条件判断。

If标签(条件判断标签)
闭合  非闭合标签
属性  condition(必须):要判断的条件
elseif标签(条件判断标签)
闭合  闭合标签
属性  condition(必须):要判断的条件
else标签(条件判断标签)
闭合  闭合标签
属性  无

用法示例:

value1
value2
value3


在condition属性中可以支持eq等判断表达式,同上面的比较标签,但是不支持带有”>”、”

value1
     value2


必须改成:

value1
value2


除此之外,我们可以在condition属性里面使用php代码,例如:

ThinkPHP
other Framework


condition属性可以支持点语法和对象语法,例如:
自动判断user变量是数组还是对象

ThinkPHP
other Framework


或者知道user变量是对象

ThinkPHP
other Framework



由于if标签的condition属性里面基本上使用的是php语法,尽可能使用判断标签和Switch标签会更加简洁,原则上来说,能够用switch和比较标签解决的尽量不用if标签完成。因为switch和比较标签可以使用变量调节器和系统变量。如果某些特殊的要求下面,IF标签仍然无法满足要求的话,可以使用原生php代码或者PHP标签来直接书写代码。

原文:http://doc.thinkphp.cn/manual/if.html
Statement:
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