Home >Backend Development >PHP Tutorial >The difference between empty, is_null and isset

The difference between empty, is_null and isset

WBOY
WBOYOriginal
2016-07-30 13:30:34998browse

empty(), is_null(), isset() truth table (difference)

1. When the variable is undefined, is_null() and "the parameter itself" are not allowed to be used as parameters for judgment, and a Notice warning error will be reported;
2. Empty and isset will first check whether the variable exists, and then detect the variable value. And is_null and "the parameter itself" just check the variable value directly to see if it is null, so if the variable is not defined, an error will occur!

3. isset(): only if null and undefined, return false;
4. empty(): "", 0, "0", NULL, FALSE, array(), undefined, all return false;
5. is_null(): only determines whether it is null, and reports a warning if it is not defined;
6. The variable itself is used as a parameter, consistent with empty(), but when accepting undefined variables, a warning is reported;
"", 0, "0" , NULL, FALSE, and array(), empty() has the same result as "the variable itself is used as a parameter" and is treated as "empty", while isset() and is_null () are treated as null only. "Empty" is processed (it is worth noting that false is not considered empty)
empty()
If the variable is a non-empty or non-zero value, empty() returns FALSE. In other words, "", 0, "0", NULL, FALSE, array(), var $var, undefined, and objects without any properties will be considered empty, and TRUE will be returned if var is empty. .
isset()
If the variable exists and the value is not NULL, it returns TRUE, otherwise it returns FALSE (including undefined). The variable value is set to: null, and the return value is also false; after unsetting a variable, the variable is canceled. Note that isset handles NULL value variables specially.
  is_null()
  Detect whether the incoming value [value, variable, expression] is null. Only one variable is defined and its value is null, it returns TRUE. Others return FALSE [After undefined variables are passed in Something can go wrong! 】.

The difference between empty, is_null and isset

The above has introduced the differences between empty, is_null and isset, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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
Previous article:PHPExcel style controlNext article:PHPExcel style control