Home > Backend Development > PHP Tutorial > PHP method to determine whether a variable is 0

PHP method to determine whether a variable is 0

怪我咯
Release: 2023-03-13 18:26:02
Original
9995 people have browsed it

PHP functions:empty() and isset() are both functions that determine whether the variable has been configured, but there are still certain differences when using them.

empty() function is used to test whether the variable has been configured. If the variable already exists, is not an empty string, or is nonzero, a false value is returned; otherwise, true is returned.

isset() function is used to test whether the variable has been configured. Returns true if the variable already exists. Other situations return a false value.

It can be seen from the definitions of the above two functions that empty() and isset() have something in common: both can determine whether a variable is empty, and both return boolean type, that is, true or false. The most obvious difference between them is that the Boolean value returned is exactly the opposite.

In addition, the biggest difference between them is the judgment of 0. If you use empty to judge, it will be considered to be empty, and if you use isset, it will be considered not to be empty. For example:

<?php
          var $a=0;
           //empty($a)返回true
           if(empty($a)){
                 echo "判断结果是空"
           }
          //isset($a)返回true
           if(isset($a)){
                 echo "判断结果不是空"
           }
 ?>
Copy after login

The above is the detailed content of PHP method to determine whether a variable is 0. 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