PHP empty,is_null,isset The difference between the detailed _php tutorial

Source: Internet
Author: User
PHP has a lot of functions similar to the function, but there are subtle differences, as this article all the analysis of the Is_null,empty,isset three functions, no effort, it is not easy to really understand the amount! below to follow the webmaster to specifically understand the difference between the three functions!

Let's take a look at the functional descriptions of these 3 functions

Isset evaluates if the variable already exists and returns TRUE if the variable exists, otherwise FALSE.

Empty determines if the variable is empty, and empty () returns FALSE if the variable is a non-null or nonzero value. In other words, "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any properties will be considered empty, and TRUE if the variable is empty.

Is_null to determine if a variable is null

How, the general is this explanation, but this explanation has been very confusing, the following combination of specific examples to analyze it!

From this we can see that as long as the variable is "" or 0, or false and null, any of these values will return true.

Isset only determines if the variable exists, and as long as you are not NULL or unassigned, the returned result is true. If you use Isset () to test a variable that is set to NULL, FALSE is returned. Also note that a null byte ("s") is not equivalent to a null constant in PHP.

And Is_null is exactly the inverse of isset, we can think of it as!isset, is a reverse operation of Isset.

From the example above, we can also draw the following conclusions (which will be used frequently in future programming):

Suppose $var is any type

When empty ($var) is true, (bool) ($var) is false. Vice versa.

When Is_null ($var) is true, Isset ($var) is false. Vice versa.

For example:

$i = $j +1;

The Is_null ($j) Here is true (it can be understood that isset ($J) is false because there is no prior declaration $j this variable)

Another two points to note are :

(1) empty () detects only variables and detects anything that is non-variable will result in parsing errors. In other words, the statement behind will not work: Empty (Addslashes ($name)).

(2) Isset () can only be used for variables, because passing any other parameter will result in parsing errors. To detect if a constant is set, use the defined () function.

Articles you may be interested in

    • Usage and differences in PHP that jump out of multiple loops using Break,continue,goto,return,exit
    • Usage differences for tinyint, smallint, int, and bigint types in MySQL
    • The usage and difference of echo,print,print_r,var_export,var_dump in PHP
    • The difference between execute and query methods in thinkphp
    • The difference between readonly, disabled, display and visible
    • Scrollheight,scrollwidth,scrollleft,scrolltop and other differences in JavaScript pee
    • PHP Merge array + vs. Array_merge
    • PHP $this, Static, final, const, self, and several other key words to use

http://www.bkjia.com/PHPjc/764073.html www.bkjia.com true http://www.bkjia.com/PHPjc/764073.html techarticle PHP has a lot of functions similar to the function, but there are subtle differences, as this article all the analysis of the Is_null,empty,isset three functions, no effort, it is not easy to really engage in ...

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