ThinkPHP模板判断输出Empty标签用法详解

来源:互联网 发布:服务器数据丢失的原因 编辑:程序博客网 时间:2024/04/28 02:57

  1. ThinkPHP模板empty标签用来判断模板变量是否为空值,其功能相当于PHP中的empty()函数行为。empty标签使用格式如下: 
  2. <empty name="变量名">要输出的内容</empty>
  3. 具体用法如下例所示: 
  4. <empty name="username">username 为空值</empty
  5.  
  6. 该例子等同于:
  7. <?php
  8. if(empty($username)){
  9.   echo 'username 为空值';
  10. }
  11. ?>
  12.  
  13. 如果判断非空值可使用notempty标签,如下所示:
  14. <notempty name="username">username 不为空</notempty>
  15. 两个标签合并起来可写成:
  16. <empty name="username">username 为空值<else/>username 不为空</empty>
  17.  
复制代码

0 0