Summary of usage of isset () and unset () functions in PHP

Source: Internet
Author: User
Tags bool constant php language mixed parse error set set

  This article is mainly in PHP isset () and unset () the use of the function of a detailed introduction, the need for friends can come to the reference, I hope to help you.

Isset (PHP 3, PHP 4, PHP 5)   Isset--detect variables are set   describe bool Isset (mixed var [, mixed Var [, ...]]) if VAR exists then return Return TRUE, or FALSE.   If you have freed a variable using unset (), it will no longer be isset (). If you use Isset () to test a variable that is set to NULL, it returns FALSE. Also note that a null byte ("") is not equivalent to PHP's null constant.   WARNING: isset () can only be used for variables because passing any other parameter will result in a parse error. To detect if a constant is set, use the defined () function.     Code as follows: <?php $var = ';  //The result is TRUE, so the text behind will be printed. if (Isset ($var)) {     print "This var is set set sets so I'll print.";}  //In the example below, we will use the Var_dump output The return value of the Isset ().   $a = "test"; $b = "Anothertest";   Var_dump (Isset ($a));      //TRUE var_dump (isset ($a, $b)); TRUE   unset ($a);   Var_dump (Isset ($a));    //FALSE Var_dump (isset ($a, $b)); FALSE   $foo = NULL; Var_dump (Isset ($foo));  /FALSE?>     This is also valid for the elements in the array: The code is as follows: <?php $a = array (' Test ' => 1, ' hello ' => NULL);   Var_dump (isset ($a [' Test '])]; &nbsp          //TRUE var_dump (isset ($a [' foo ']);            //FALSE Var_dump (isset ($a [' hello ']));          //FALSE  //key ' hello ' value equals NULL, so it is considered an open value. If you want to detect NULL key values, try the bottom method.   Var_dump (array_key_exists (' hello ', $a)); TRUE?>     NOTE: Because this is a language structure and not a function, it cannot be invoked by a "variable function".   Rational Application of PHP functions Isset () can help us to detect whether the 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 about the PHP language, you should know that it is a function-based HTML scripting language. The vast library of functions supports the implementation of the PHP language function. Here's a brief introduction to the usage of PHP function isset ().       Format: bool Isset (mixed var [, mixed Var [, ...]])   function: Detect whether the variable is set to the   return value:   Returns FAL if the variable does not exist se  if the variable exists and its value is NULL, also returns false  if the variable exists and the value is not NULL, then return ture   Check multiple variables simultaneously, each item meets the previous requirement to return TRUE, otherwise the result is FALSE   Version: PHP 3, PHP 4, PHP 5   MORE:   after using unset () to release the variable, it will no longer be isset ().   PHP function isset () can only be used for variables, passing any other parameters will result in parsing errors.   Detect whether constants are set to use the defined () function.   unset ()     destroy 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 true function: it is now a statement. So that there is no return value, trying 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.