Hướng dẫn php isset condition

[PHP 4, PHP 5, PHP 7, PHP 8]

issetDetermine if a variable is declared and is different than null

Description

If a variable has been unset with the unset[] function, it is no longer considered to be set.

isset[] will return false when checking a variable that has been assigned to null. Also note that a null character ["\0"] is not equivalent to the PHP null constant.

If multiple parameters are supplied then isset[] will return true only if all of the parameters are considered set. Evaluation goes from left to right and stops as soon as an unset variable is encountered.

Parameters

var

The variable to be checked.

vars

Further variables.

Return Values

Returns true if var exists and has any value other than null. false otherwise.

Examples

Example #1 isset[] Examples



and

will always echo 'false'. because the isset[] accepts VARIABLES as it parameters, but in this case, $foo->bar is NOT a VARIABLE. it is a VALUE returned from the __get[] method of the class Foo. thus the isset[$foo->bar] expreesion will always equal 'false'.

ayyappan dot ashok at gmail dot com

6 years ago

Return Values :
Returns TRUE if var exists and has value other than NULL, FALSE otherwise.


Could any one explain me in clarity.

mandos78 AT mail from google

14 years ago

Careful with this function "ifsetfor" by soapergem, passing by reference means that if, like the example $_GET['id'], the argument is an array index, it will be created in the original array [with a null value], thus causing posible trouble with the following code. At least in PHP 5.

For example:



will print

Array
[
]
Array
[
    [unsetindex] =>
]

Any foreach or similar will be different before and after the call.

Cuong Huy To

11 years ago

1] Note that isset[$var] doesn't distinguish the two cases when $var is undefined, or is null. Evidence is in the following code.

Chủ Đề