The use of PHP isset functions

Source: Internet
Author: User
Tags set set

The Isset function detects if a variable is set.

Format: bool Isset (mixed var [, mixed Var [, ...])

return value:

Returns False if the variable exists and its value is NULL, returns FALSE if the variable exists and the value is not NULL, returns TRUE if the ture checks multiple variables at the same time, or False if unset is already used ( After releasing a variable, 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.

Warning: 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.

Example 1:

    1. $var = ";
    2. if (Isset ($var)) {
    3. Print "This var was set set so I'll print.";
    4. }//in the example below, we will use the Var_dump function to output the return value of the Isset ().
    5. $a = "Test";
    6. $b = "Anothertest";
    7. Var_dump (Isset ($a)); TRUE
    8. Var_dump (Isset ($a, $b)); TRUE
    9. unset ($a);
    10. Var_dump (Isset ($a)); FALSE
    11. Var_dump (Isset ($a, $b)); FALSE
    12. $foo = NULL;
    13. Var_dump (Isset ($foo)); FALSE
    14. ?>
Copy Code

Example 2:

    1. $a = array (' test ' = = 1, ' hello ' = NULL);

    2. Var_dump (isset ($a [' test '));//TRUE

    3. Var_dump (isset ($a [' foo '));//FALSE
    4. Var_dump (isset ($a [' hello '));//FALSE

    5. ' Hello ' equals NULL, so it is considered to be unassigned.

    6. If you want to detect NULL key values, you can try the methods below.
    7. Var_dump (array_key_exists (' hello ', $a)); TRUE
    8. ?>

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