Determines whether php variables are defined and empty.

Source: Internet
Author: User
Determine whether php variables are defined. is it empty isset () [1] Returns? TRUE? If? Var? Existsandhasvalueotherthan? NULL ,? FALSE? Otherwise. the input can be multiple variables. If all the variables are true, true emp is returned to determine whether php variables are defined and empty.

Isset () [1]

Returns?TRUE? If?Var? Exists and has value other?NULL,?FALSE? Otherwise.

The input can be multiple variables. only when all the variables are true returns true.

Empty () [2]

Returns?FALSE? If?Var? Has a non-empty and non-zero value.

The following things are considered to be empty:

  • "" (An empty string)
  • 0 (0 as an integer)
  • "0" (0 as a string)
  • NULL
  • FALSE
  • Array () (an empty array)
  • Var $ var; (a variable declared, but without a value in a class)

The input can only be a variable.

Is_null () [3]

Returns?TRUE? If?Var? Is? Null ?,?FALSE? Otherwise.

?

?

?? A variable is considered to be? Null? If:

  • It has been assigned the constant?NULL.

  • It has not been set to any value yet.

  • It has been? Unset ().? ?

?

?

$ X Using PHP functions for variables?? For comparison Expression gettype () empty () is_null () isset () if ($ x) Boolean
$ X = ""; String TRUE FALSE TRUE FALSE
$ X = null; NULL TRUE TRUE FALSE FALSE
Var $ x; NULL TRUE TRUE FALSE FALSE
$ X? Is undefined NULL TRUE TRUE FALSE FALSE
$ X = array (); Array TRUE FALSE TRUE FALSE
$ X = false; Boolean TRUE FALSE TRUE FALSE
$ X = true; Boolean FALSE FALSE TRUE TRUE
$ X = 1; Integer FALSE FALSE TRUE TRUE
$ X = 42; Integer FALSE FALSE TRUE TRUE
$ X = 0; Integer TRUE FALSE TRUE FALSE
$ X =-1; Integer FALSE FALSE TRUE TRUE
$ X = "1 "; String FALSE FALSE TRUE TRUE
$ X = "0 "; String TRUE FALSE TRUE FALSE
$ X = "-1 "; String FALSE FALSE TRUE TRUE
$ X = "php "; String FALSE FALSE TRUE TRUE
$ X = "true "; String FALSE FALSE TRUE TRUE
$ X = "false "; String FALSE FALSE TRUE TRUE

?

(The original source is not found in the table above. please let me know)

What if the variable is an object?

?

Expression gettype () empty () is_null () isset () if ($ x) Boolean
$ X = new object ()? Object FALSE FALSE TRUE TRUE

?

Refer:

[1] http://php.net/manual/en/function.isset.php

[2] http://www.php.net/manual/en/function.empty.php

[3] http://www.php.net/manual/en/function.is-null.php

?

?

Http://blog.csdn.net/autofei/archive/2010/05/24/5619004.aspx

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.