Differences between empty () and isset functions

Source: Internet
Author: User
Tags type null
Empty () function: mainly determines whether the variable is not empty or not 0. If the variable value is not null or not 0, true is returned; otherwise, false is returned.

Differences between empty () and isset () functions:

Empty () function: mainly determines whether the variable is not empty or not 0. If the variable value is not null or not 0, true is returned; otherwise, false is returned.


Description: bool empty (mixed $ var)

If var is a non-null or non-zero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, array (), var $ var; and objects without any attributes will be considered empty, if var is null, TRUE is returned.

When converted to boolean, the following values are considered FALSE:

  • Boolean value FALSE
  • Integer value 0 (0)
  • Floating point value: 0.0 (0)
  • Empty string and string "0"
  • Array that does not contain any elements
  • Objects that do not include any member variables (applicable only to PHP 4.0)
  • Special type NULL (including unassigned variables)
  • SimpleXML object generated from an XML document without any tags
Isset () function: mainly determines whether the variable has been set (not null). if it has been set, true is returned; otherwise, false is returned. it indicates bool isset (mixed $ var [, mixed $...])

Check whether the variable is set and not NULL.

If unset () is used to release a variable, it will no longer be isset (). If you use isset () to test a variable that is set to NULL, FALSE is returned. Note that a NULL byte ("\ 0") is not equivalent to the NULL constant of PHP.

Example 1:

$var; var_dump($var); //NULL echo ""; var_dump(empty($var));  //true; NULLecho ""; var_dump(isset($var)); //false; NULL 

Example 2:

$ Var = '';

Var_dump ($ var); // string echo ""; var_dump (emptyempty ($ var); // true; the variable value is empty echo ""; var_dump (isset ($ var); // variable set; non-NILL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.