Differences and relationships between empty and isset

Source: Internet
Author: User
The difference and connection between empty and isset PHP is a weak type language. it is different from C #/JAVA. when declaring a variable, you do not need to declare its type. therefore, there may be many special values and occasionally some strange problems.

In the afternoon, I stole a truth table from a foreign website. it was very intuitive and detailed ~ Send it quickly.

Differences and relationships between empty and isset

To talk about their connection, empty () and isset () are both variable processing functions. they are used to determine whether the variables have been configured, it is because of their great similarity in the process of processing variables that they lack understanding of their relationships. Considering the functions empty () and isset (), we will confuse people and give them a different angle. The processing objects of empty () and isset () are almost undefined variables, 0, empty strings.
If the variable is 0, empty () returns TRUE, and isset () returns TRUE;

If the variable is a null string, empty () returns TRUE, and isset () returns TRUE;

If the variable is not defined, empty () returns TRUE, and isset () returns FLASE;

Empty () is described as follows:
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.
Isset () is described as follows:
Isset () check whether the variable is set
Description: bool isset (mixed var [, mixed var [,...])
If var exists, TRUE is returned; otherwise, FALSE is returned.
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.
Warning: isset () can only be used for variables, because passing any other parameter will cause a parsing error. To check whether a constant has been set, use the defined () function.
You can use the isset function to determine whether a variable has been declared.
You can use the empty function to determine whether a variable has been assigned data and is not empty.
To determine whether a variable exists and is not empty, use the isset function and the empty function.

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.