The empty () function and the isset () function in PHP

Source: Internet
Author: User

In the development process, often encountered in the judgment of the existence of variables and whether it is empty, especially the array, if the access to a non-existent element of the array, there will be a notice level of error burst, but also a logic is not rigorous performance.

First, look at the empty () function:

Determines whether a function is empty. So what is the case in PHP that is considered empty? The first is that the variable does not exist , and the second is that the value of this variable is equal to FALSE. That is, empty ($var) is equivalent to!isset ($var) | | $var = = FALSE.


Then look at the Isset () function:

Determine if a variable exists and his value is not equal to null.

If the unset ($var), the $var will not exist;

If a variable is given NULL, the function also returns FALSE;

And this function can have more than one parameter, which returns TRUE only if all arguments are present and the value is not equal to NULL.

Because NULL is also a value equivalent to a value of false, the emtpy () function equals isset () plus a value that determines whether the variable is equal to the other equivalent of false.

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.