SHARE

isset() Function PHP

In PHP isset function is a buit in function . User can just call and use it . It is use to check the condition that variable value is not NULL and variable assigned any value .

Example of Null Variable

<?php
if(isset($name)){
echo 'variable is set';
}
else{
echo 'variable is not set';
}
?>

Working

isset() function check that the variable “$name” value is not set . so the php code echo second string “variable is not set

if statement check the condition and check that is $name has any value or it is NULL .

Learn about if() statement
if( isset($name) )
If the condition is true and variable “$name” assigned any value then run the first code block and echo result “variable is set”

{
echo 'variable is set';
}

If the condition is not true and variable $name is NULL or not value assigned then second code block is executed . and the result is “variable is not set”

isset() function check that the variable “$name” value is not set . so the php code echo second string “variable is not set

Multiple parameters In isset()

You can check multiple variable values with isset function using multiple parameters .

Syntax

isset(variable1 , variable2 ,variable3 ….. )

Example

<?php
$name1="This is name 1 ";
$name2="This is name 2 ";
if(isset($name,$name2))
{
echo 'variable is set';
}
else{
echo 'variable is not set';
}
?>

Working With Multiple Parameters

When user check multiple variables with isset then the result is only true if both of variable are set . For example if one variable is set and second is not set then still the result is false .

Result

In this example isset() check two variables . Both are set and assigned value so the condition is true and result is “Variable is set“.

If one variable value is deleted and run the code again then condition is false so the second code is executed “Variable is not set

Reference about isset()