Empty () and isset () functions in PHP

Source: Internet
Author: User
During the development of empty () and isset () functions in PHP, it is often possible to determine whether the variable does not exist or whether it is null, especially the array, if an element that does not exist in the access array, there will be a Notice-level error, which is also a result of not rigorous logic.

First, let's take a look at the empty () function:

Determines whether a function is null. In PHP, what kind of situation is considered empty?The first is that this variable does not exist.;The second is that the value of this variable is equivalent to FALSE.. That is to say, empty ($ var) is equivalent! Isset ($ var) | $ var = FALSE.


Let's take a look at the isset () function:

Judge a variableExistAndThe value is not NULL..

If unset ($ var) is used, $ var does not exist;

If a variable is NULL, the function returns FALSE;

In addition, this function can have multiple parameters. TRUE is returned only when all parameters exist and the value is not equal to NULL.

Because NULL is also a value equivalent to FALSE, the emtpy () function equals isset () and determines whether the variable is equal to other values equivalent to 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.