PHP Tutorial - PHP isset() function






Checking Whether a Variable Is Set: isset()

Syntax

PHP isset() function has the following syntax.

isset($variableName);

Parameter

  • $variableName - variable to check

Return

The isset() function returns true or false depending on whether the variable has a value assigned to it.

Example

Is the variable check


<?PHP/*from   ww w.j a  v  a  2 s . c  o  m*/
$foo = 1; 
if (isset($foo)) { 
       echo "Foo is set\n"; 
} else { 
       echo "Foo is not set\n"; 
} 

if (isset($bar)) { 
       echo "Bar is set\n"; 
} else { 
       echo "Bar is not set\n"; 
} 
?>

The code above generates the following result.