A brief analysis of PHP isset () and unset () function usage

Source: Internet
Author: User
Tags php language parse error
    1. $var = ";
    2. The result is true, so the text behind will be printed.
    3. if (Isset ($var)) {
    4. Print "This var was set set so I'll print.";
    5. }
    6. In the example below, we will use Var_dump to output the return value of Isset ().
    7. $a = "Test";
    8. $b = "Anothertest";
    9. Var_dump (Isset ($a)); True
    10. Var_dump (Isset ($a, $b)); True
    11. unset ($a);
    12. Var_dump (Isset ($a)); False
    13. Var_dump (Isset ($a, $b)); False
    14. $foo = null;
    15. Var_dump (Isset ($foo)); False
    16. ?>
Copy Code

This is equally valid for elements in an array:

    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. The value of the key ' hello ' is equal to NULL, so it is considered to be an unassigned value.
    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

Note: Because this is a language structure and not a function, it cannot be called by a "variable function". Reasonable application of PHP function Isset () can help us to detect whether a variable is set. Returns FALSE if the variable does not exist, and returns ture if the variable exists and the value is not NULL. By learning the language of PHP, you should know that it is a function-based HTML scripting language. The large library of functions supports the implementation of PHP language functions. Under

Related usage of PHP function isset ().

Format: bool Isset (mixed var [, mixed Var [, ...]) Function: Detects if a variable has a return value: If the variable does not exist, it returns False if the variable exists and its value is NULL, and returns FALSE if the variable exists and the value is not NULL, returns True if the ture checks for multiple variables at the same time, or if each item conforms to the previous requirement, the result is False version: PHP 3, PHP 4, PHP 5

More information: After releasing a variable with unset (), it will no longer be isset (). PHP functions Isset () can only be used for variables, and passing any other parameter will result in parsing errors. Detects if a constant is set to use the defined () function. Unset () destroys the specified variable. Note in PHP 3, unset () returns True (actually an integer value of 1), whereas in PHP 4, unset () is no longer a real function: it is now a statement. Thus there is no return value, and attempting to get the return value of unset () will result in a parse error.

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