Determine if the PHP variable is undefined or empty

Source: Internet
Author: User
Determine if the PHP variable is defined and is empty

Isset () "1"

Returns? TRUE? If? var? exists and have value other than? NULL,? FALSE? otherwise.

Input can be multiple variables, only when all variables are true, return true

Empty () "2"

Returns? FALSE? If? varhas a non-empty and Non-zero value.

The following things is 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)

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 no been set to any value yet.

  • It has been? unset (). ? ?

?

?

$x Use PHP functions for variables?? to compare 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 above table did not find the original source, who knows please tell me)

What if the variable is an object?

?

Expression GetType () empty () Is_null () isset () if ($x) Boolean
$x = new Object ()? Object FALSE FALSE TRUE TRUE

?

Reference:

"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

  • Related Article

    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.