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

The difference between empty and isset

WBOY
Release: 2016-07-29 08:57:46
Original
953 people have browsed it
boolempty(mixed$var)

Determining whether a variable is empty can also be understood as judging whether the variable is false. Returns a Boolean value of true or false.

In addition to not generating a warning when the variable has no value, empty($var) is the antonym of (bool)$var.

If $var can be converted to boolean false, the return value of empty() is true, otherwise, it returns false.

The following seven values, when converted to boolean (same as bool), are considered false:

  • boolean false itself
  • integer 0
  • float 0.0
  • string '0' or All values ​​other than "0"
  • empty string'' or ""
  • empty array array() or []
  • NULL or null

are treated as true.

var_dump( (bool)false );

var_dump( (bool)0 );

var_dump( (bool)0.0 );

var_dump( (bool)'0' );

var_dump( (bool)'' );

var_dump( (bool)array() );

var_dump( (bool)null );

?>

empty returns true in seven cases of false , the rest return false.

bool isset(mixed$var[, mixed$...] )

Determine whether the variable is set. If the value of a variable is not null, it means that the variable is set, and true is returned; otherwise, false is returned.

A variable is considered null in the following situations:

  • is assigned to NULL
  • has not been assigned or defined
  • has been unset() unset

isset() Three types of NULL Returns false in this case, and returns true in all other cases.

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

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