SoFunction
Updated on 2025-04-04

Analysis of the comparison label usage of Thinkphp5.0 framework view view

This article describes the usage of the comparison tags of Thinkphp5.0 framework view. Share it for your reference, as follows:

{eq name="a" value="10"}
  <p>equal</p>
{else/}
<p>不equal</p>
{/eq}

{equal name="a" value="10"}
  <p>equal</p>
{else/}
  <p>不equal</p>
{/equal}

{neq name="a" value="10"}
  <p>Not equal</p>
{else/}
  <p>equal</p>
{/neq}

{notequal name="a" value="10"}
  <p>Not equal</p>
{else/}
  <p>equal</p>
{/notequal}

{egt name="a" value="10"}
  <p>Greater than or equal to</p>
{else/}
  <p>Less than</p>
{/egt}

! ! ! If you need to use two variables to compare in the template, the value of the value needs to be marked with the $ sign:
$b can be used with double quotes or single quotes.

{eq name="a" value="$b"}
  <p>variablea和variablebequal</p>
{else/}
  <p>variablea和variableb不equal</p>
{/eq}

Conditional judgment label:

Switch tag:

{switch name='user_level'}
  {case value='1'}<p>VIPmember</p>{/case}
  {case value='2'}<p>钻石member</p>{/case}
  {case value='3|4'}<p>铂金member</p>{/case}
  {case value='5'}<p>黄金member</p>{/case}
  {default /}<p>普通member</p>
{/switch}

Range tag:

<!-- typeequalinUse -->
{range name="user_age" value="10,11,12,13" type="in"}
<p>User age is10、11、12、13one of the</p>
{else/}
<p>User age is not10、11、12、13one of the</p>
{/range}

<!-- typeequalbetweenUse -->
{range name="user_age" value="10,13" type="between"}
<p>The user is at the age of10arrive13between</p>
{else/}
<p>User age is not10arrive13between</p>
{/range}

between tags:

{between name="user_age" value="10,13"}
<p>The user is at the age of10arrive13between</p>
{else/}
<p>User age is not10arrive13between</p>
{/between}

Define tag:

<!-- Determine whether a constant is defined -->
{defined name="APP_NAME"}
<p>Define constantsAPP_NAME</p>
{else/}
<p>Undefined constantAPP_NAME</p>
{/defined}

if tag:

<!-- ifLabel -->
{if condition="($a > 10) and ($a < 20)"}
<p>variableaGreater than10,Less than20 </p>
{else/}
<p>variableaLess than等于10或Greater than等于20</p>
{/if}

For more information about thinkPHP, please visit the special topic of this site:ThinkPHP Introduction Tutorial》、《Summary of the operation skills of thinkPHP templates》、《Summary of common methods of ThinkPHP》、《Codeigniter Introductory Tutorial》、《Advanced tutorial on CI (CodeIgniter) framework》、《Zend FrameWork framework tutorial"and"PHP template technical summary》。

I hope that the description in this article will be helpful to everyone's PHP programming based on the ThinkPHP framework.