The PHP function isset () can only be used for variables.

Source: Internet
Author: User

Through

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

Function: checks whether variables are set.

Return Value:

If the variable does not exist, FALSE is returned.
If the variable exists and its value is NULL, FALSE is returned.
If the variable exists and the value is not NULL, true is returned.

When multiple variables are checked at the same time, TRUE is returned only when each individual item meets the previous requirement; otherwise, the result is FALSE.

Version: PHP 3, PHP 4, PHP 5

More instructions:

When unset () is used to release a variable, it is no longer an isset ().
The PHP function isset () can only be used for variables. Passing any other parameter will cause a parsing error.
Checks whether the defined () function has been set for constants.

 
 
  1. <? Php
  2. $ Var = '';
  3. If (isset ($ var) // null, 0, false
    Isset determines TRUE, so
    .
  4. Print "blank value-> isset = true .";
  5. $ Var = NULL; if (! Isset ($ var ))//
    If the value is NULL, isset determines FALSE.
  6. Print "NULL value-> isset = false .";
    // The following uses 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 ($ );
  12. Var_dump (isset ($ a); // FALSE
  13. Var_dump (isset ($ a, $ B); // FALSE
  14. ?>

The PHP function isset () is also suitable for checking array and object elements. If an array or object instance is not defined, false is returned for detecting the array element or object element.

 
 
  1. <? Php
  2. $ A = array ('test' => 1, 'Hello' => NULL );
  3. Var_dump (isset ($ a ['test']); // TRUE
  4. Var_dump (isset ($ a ['foo']); // FALSE
  5. Var_dump (isset ($ a ['hello']); // FALSE
  6. // The value of the 'hello' key is NULL, so it is considered as an unset value.
  7. // If you want to check the NULL key value, try the following method.
  8. Var_dump (array_key_exists ('hello', $ a); // TRUE
  9. ?>

Note: because this is a language structure rather than a function, the PHP function isset () cannot be called by variable functions.


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.