Differences between is_null, empty, isset, and unset in php

Source: Internet
Author: User
This article describes the differences among is_null, empty, isset, and unset in php. For more information, see Is_null, empty, isset, and unset. Let's take a look at the descriptions of these four functions.

Isset determines whether a variable already exists (configuration)
Unset: delete (release) the variable.
Empty determines whether the variable is null
Is_null determines whether the variable is NULL
OK. You have started to engage. In the beginning, except for unset, all the other three functions are judgment functions. unset first goes out, because it will not be wrong, followed by is_null. we can regard it! Isset is an inverse operation of isset. The following table clearly describes the relationship between them:

The Code is as follows:


Empty is_null isset
$ A = "true false true
$ A = null true false
Var $ a true false
$ A = array () true false true
$ A = false true
$ A = 15 false true
$ A = 1 false true
$ A = 0 true false true
$ A = "0" true false true
$ A = "true" false true
$ A = "false true



From this, we can find that as long as the variable is "" or 0, or false or null, empty will return true, and isset is to determine whether the variable exists, as long as this variable is not null or not assigned a value, the returned result is true, and is_null is exactly the reverse result of isset.

Of course, if you only want to do the following:
Echo! Isset ($ _ GET ['a']); // if the value of variable a is not obtained
Echo empty ($ _ GET ['a']); // if the value of variable a is null

The results are the same and can be used.

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.