PHP isset() Function

PHP isset() Function is used to check whether the variable is set or declared. Also checks a variable is empty.  PHP isset() function is PHP built-in function.

PHP isset() Function checks variable is not NULL.  PHP isset() Function also checks variable is set or not.

Syntax for isset:

isset(mixed $var, ....);

Parameter,

$var :  Required. It specifies the variable to check.
.... : Optional. Pass Multiple variable.

Return Values for isset :

PHP isset() function returns true if the variable exists and is not NULL, otherwise it returns false.

If multiple variables are passed, then this function will return true only if all of the variables are set.

Let's see below example to understand php isset() Function in details.

Example :

<?php
$var1 = 5;
// Returns true because $var is set because it doesn't have null value.
if (isset($var1)) {
echo "<br> Variable 'var1' is set.";
}

$var2 = null;
// Returns false because $var2 is NULL.
if (isset($var2 )) {
echo "<br>Variable 'var2 ' is set.";
}else
{
echo "<br>Variable 'var2 ' is not set.";
}

$var3 = 0;
// Returns true because $var3 is not NULL.
if (isset($var3 )) {
echo "<br>Variable 'var3 ' is set.";
}
?>

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

83433