Home > PHP Framework > ThinkPHP > How to determine whether a variable is empty in thinkphp5

How to determine whether a variable is empty in thinkphp5

WBOY
Release: 2022-04-07 15:51:49
Original
3555 people have browsed it

In thinkphp, you can use the empty tag to determine whether a variable is empty. The function of this tag is to determine whether a template variable is empty. Its function is equivalent to the empty() function in PHP, and the syntax is "< empty name="Variable name">Content to be output".

How to determine whether a variable is empty in thinkphp5

The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.

thinkphp5 determines whether the variable is empty

ThinkPHP template empty tag is used to determine whether the template variable is empty. Its function is equivalent to the empty() function behavior in PHP. The empty tag usage format is as follows:

<empty name="变量名">要输出的内容</empty>
Copy after login

The specific usage is as shown in the following example:

<empty name="username">username 为空值</empty>
Copy after login

This example is equivalent to:

<?php
if(empty($username)){
  echo &#39;username 为空值&#39;;
}
?>
Copy after login

If you judge a non-empty value, you can use the notempty tag, as follows Shown:

<notempty name="username">username 不为空</notempty>
Copy after login

The two tags can be combined to write:

<empty name="username">username 为空值<else/>username 不为空</empty>
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine whether a variable is empty in thinkphp5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template