Sample test for PHP empty (), Isset () and Is_null ()

Source: Internet
Author: User
Example test for PHP empty (), Isset () and Is_null ()

The usage of the three functions for PHP (), Isset () and Is_null () has been discussed a lot, and a lot of data may not be clear. Here again, but not from the concept, the direct use of program examples to speak, it should be more profound memory.

The types of tests are as follows:

$a;

$b= false;

$c= '';

$d= 0;

$e= null;

$f= array();

?>

Empty ()

The first is the empty var_dump output:

var_dump(empty($a));

var_dump(empty($b));

var_dump(empty($c));

var_dump(empty($d));

var_dump(empty($e));

var_dump(empty($f));

?>

The program output is:

bool(true)

bool(true)

bool(true)

bool(true)

bool(true)

bool(true)

As you can see from the code, empty () outputs true as long as the data type is empty or false.

Isset ()

And look at the output of Isset:

var_dump(isset($a));

var_dump(isset($b));

var_dump(isset($c));

var_dump(isset($d));

var_dump(isset($e));

var_dump(isset($f));

// 输出

bool(false)

bool(true)

bool(true)

bool(true)

bool(false)

bool(true)

You can see that isset () can only be used to determine if it is null and undefined.

Is_null ()

Finally, the output of the Is_null:

var_dump(is_null($a));

var_dump(is_null($b));

var_dump(is_null($c));

var_dump(is_null($d));

var_dump(is_null($e));

var_dump(is_null($f));

// 输出

bool(true)

bool(false)

bool(false)

bool(false)

bool(true)

bool(false)

Is_null literally means it.

This shows that empty () can be used to determine whether all data types are empty or false, and is_null is basically the same as isset, and can only be used to determine if null and undefined.

  • 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.