The difference between empty () and isset () in PHP _php tutorial

Source: Internet
Author: User

The difference between empty () and isset () in PHP


1, empty function use: detect whether the variable is null judgment: If VAR is a non-null or nonzero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any properties will be considered empty and return TRUE if Var is empty. SOURCE Manual: http://php.net/manual/zh/function.empty.php Note: empty () detects only variables and detects anything that is non-variable will result in parsing errors. $name =0; $name = "; $name =null; $name =" 0 "; $name; if (empty ($name)) {echo" OK ";//The above five notation empty ($name) are true}if (empty ($na) )//result is true because the variable $na is undefined 2, the Isset function is used: the detection variable is set to determine whether the variable is set, and is not NULL. If a variable has been freed with unset (), it will no longer be isset (). 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. The Isset function is used to detect whether this variable has been set, and in the following two cases it is assumed that Isset is a false ① $id; There is no value ② or there is no definition at all. So we recommend determining if a form is committed with data, using Isset to determine if (isset ($_get/$_post[' variable ')} {echo $_get[' variable ']}else{echo ' No data passed '} example: $a 1 = null, $a 2 = false; $a 3 = 0; $a 4 = "; $a 5 = ' 0 '; $a 6 = ' null '; $a 7 = array (); $a 8 = array (); Echo Empty ($a 1)? ' True ': ' false ';//output Trueecho empty ($a 2)? ' True ': ' false ';//output Trueecho empty ($a 3)? ' True ': ' false ';//output Trueecho empty ($a 4)? ' True ': ' false ';//output Trueecho empty ($a 5)? ' True ': ' false ';//LoseOut Trueecho empty ($a 6)? ' True ': ' false ';//output Falseecho empty ($a 7)? ' True ': ' false ';//output Trueecho empty ($a 8)? ' True ': ' false ';//Output Falseecho '
'; Echo isset ($a 1)? ' True ': ' false ';//output Falseecho isset ($a 2)? ' True ': ' false ';//output Trueecho Isset ($a 3)? ' True ': ' false ';//output Trueecho Isset ($a 4)? ' True ': ' false ';//output Trueecho Isset ($a 5)? ' True ': ' false ';//output Trueecho Isset ($a 6)? ' True ': ' false ';//output Trueecho Isset ($a 7)? ' True ': ' false ';//output Trueecho isset ($a 8)? ' True ': ' false ';//Output True 1, isset value for the variable is not assigned or NULL when the judgment is false, the rest are true;2, empty need to pay more attention to the point, according to the definition of the function to make judgments.

http://www.bkjia.com/PHPjc/1060168.html www.bkjia.com true http://www.bkjia.com/PHPjc/1060168.html techarticle the difference between empty () and isset () in PHP 1, empty function Purpose: Detect whether the variable is null judgment: If VAR is a non-null or nonzero value, empty () returns FALSE. In other words, 0, 0 、...

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