Learn What Is Isset Function With Example Using PHP

admin_img Posted By Bajarangi soft , Posted On 22-09-2020

IN PHP isset() function checks if the variable is defined and not null.If a variable is already unset with unset() function, it will no longer be set. The isset() function return false if testing variable contains a NULL value.

What does isset function in PHP

Syntax for PHP isset() Function.

isset(variable1, variable2....);


Parameter   Description

variable1    Specifies the variable to check
variable2    Specifies the variable to check and its optional
...          Optional. Another variable to check


Example(1)
 

<?php
$variable1 = "test";
// True because $variable1 is set
if (isset($variable1)) {
    echo "Variable1 is set.";
}

$variable2 = null;
// False because $variable2 is NULL
if (isset($variable2)) {
    echo "Variable2  is set.";
}
?>

In above example we created two variables.In  $variable1 we stored "test " and in $variable2 we stored "null" when variables checks in isset function condition we get know variable is null or not.

Complete code of isset() function.
 

<!DOCTYPE html>
<html>
<head>
    <title>What does isset function in PHP</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>

<body>
<div class="container">
    <br>
    <br>
    <br>
    <div class="text-center">
        <h1>PHP isset() Function</h1>
    </div>
    <br>
    <br>
    <h2></h2>
    <div class="well">
        <?php
        $variable1 = "test";
        // True because $variable1 is set
        if (isset($variable1)) {
            echo "<h1>Variable1 is set.</h1>";
        }

        $variable2 = null;
        // False because $variable2 is NULL
        if (isset($variable2)) {
            echo "<h1>Variable2  is set.</h1>";
        }
        ?>
    </div>
    <br>
</div>
</body>
</html>

Related Post