Example code for usage of the PHP isset () function and the unset () function

Source: Internet
Author: User
Tags php language parse error set set
This article is mainly for PHP isset () and unset () functions of the use of a detailed introduction, the need for friends can come to the reference, I hope to be helpful to everyone

Isset
(PHP 3, PHP 4, PHP 5)

Isset--Detect if the variable is set

Describe
BOOL Isset (mixed var [, mixed Var [, ...])
Returns TRUE if Var exists, otherwise FALSE is returned.

If a variable has been freed with unset (), 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.

The code is as follows:

<?php$var = ';//The result is TRUE, so the text behind will be printed. if (Isset ($var)) {     print "This var was set set so I'll print.";} In the example below, we will use Var_dump to output the return value of Isset (). $a = "Test"; $b = "Anothertest"; Var_dump (Isset ($a));      Truevar_dump (Isset ($a, $b)); Trueunset ($a); Var_dump (Isset ($a));     Falsevar_dump (Isset ($a, $b)); False$foo = Null;var_dump (Isset ($foo));   False?>

This is equally valid for the elements in the array:

The code is as follows:

<?php$a = Array (' Test ' = 1, ' hello ' = NULL); Var_dump (isset ($a [' Test ']);            Truevar_dump (isset ($a [' foo ']);             Falsevar_dump (isset ($a [' hello ']);           The value of the false//key ' hello ' is equal to NULL, so it is considered to be an unassigned value. If you want to detect NULL key values, you can try the methods below. Var_dump (array_key_exists (' hello ', $a)); True?>

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. Here we introduce the relevant usage of PHP function isset ().

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

Function: Detect whether the variable is set

return value:

Returns FALSE if the variable does not exist
Returns FALSE if the variable exists and its value is null
Returns TURE if the variable exists and the value is not NULL

Returns TRUE if each item meets the previous requirement when checking multiple variables at the same time, otherwise the result is FALSE

Version: PHP 3, PHP 4, PHP 5

More information:

After you use Unset () to release a variable, 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.