Phpisset function usage

Source: Internet
Author: User
Phpisset function usage

The isset function checks whether the variable is set.

Format: bool isset (mixed var [, mixed var [,...])

Return value:

If the variable does not exist, FALSE is returned. if the variable exists and its value is NULL, FALSE is also returned. if the variable exists and the value is not NULL, true is returned when multiple variables are checked simultaneously, TRUE is returned only when each individual item meets the previous requirement. Otherwise, the result is FALSE. if a variable is released using unset (), it is no longer isset (). If you use isset () to test a variable that is set to NULL, FALSE is returned. Note that a NULL byte ("\ 0") is not equivalent to the NULL constant of PHP.

Warning: isset () can only be used for variables, because passing any other parameter will cause a parsing error. To check whether a constant has been set, use the defined () function.

Example 1:

  1. $ Var = '';
  2. If (isset ($ var )){
  3. Print "This var is set so I will print .";
  4. } // In the following example, we will use the var_dump function to output the returned value of isset.
  5. $ A = "test ";
  6. $ B = "anothertest ";
  7. Var_dump (isset ($ a); // TRUE
  8. Var_dump (isset ($ a, $ B); // TRUE
  9. Unset ($ );
  10. Var_dump (isset ($ a); // FALSE
  11. Var_dump (isset ($ a, $ B); // FALSE
  12. $ Foo = NULL;
  13. Var_dump (isset ($ foo); // FALSE
  14. ?>

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' is equal to NULL, so it is considered to be unassigned.

  6. // If you want to check the NULL key value, try the following method.
  7. Var_dump (array_key_exists ('hello', $ a); // TRUE
  8. ?>

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.