<HTML ><HEAD ><TITLE >isset</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Variable Functions" HREF="ref.variables.html"><LINK REL="PREVIOUS" TITLE="is_string" HREF="function.is-string.html"><LINK REL="NEXT" TITLE="print_r" HREF="function.print-r.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.is-string.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.print-r.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.isset" ></A >isset</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN94265" ></A ><P > (PHP 3, PHP 4 )</P >isset -- Determine whether a variable is set</DIV ><DIV CLASS="refsect1" ><A NAME="AEN94268" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >isset</B > ( mixed var [, mixed var [, ...]])<BR ></BR ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > <B CLASS="function" >isset()</B > is a language construct. </P ></BLOCKQUOTE ></DIV ><P > Returns <TT CLASS="constant" ><B >TRUE</B ></TT > if <TT CLASS="parameter" ><I >var</I ></TT > exists; <TT CLASS="constant" ><B >FALSE</B ></TT > otherwise. </P ><P > If a variable has been unset with <A HREF="function.unset.html" ><B CLASS="function" >unset()</B ></A >, it will no longer be <B CLASS="function" >isset()</B >. <B CLASS="function" >isset()</B > will return <TT CLASS="constant" ><B >FALSE</B ></TT > if testing a variable that has been set to <TT CLASS="constant" ><B >NULL</B ></TT >. Also note that a <TT CLASS="constant" ><B >NULL</B ></TT > byte (<TT CLASS="literal" >"\0"</TT >) is not equivalent to the PHP <TT CLASS="constant" ><B >NULL</B ></TT > constant. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Warning: </B > <B CLASS="function" >isset()</B > only works with variables as passing anything else will result in a parse error. For checking if <A HREF="language.constants.html" >constants</A > are set use the <A HREF="function.defined.html" ><B CLASS="function" >defined()</B ></A > function. </P ></BLOCKQUOTE ></DIV ><P > <DIV CLASS="informalexample" ><A NAME="AEN94304" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $var = ''; // This will evaluate to &true; so the text will be printed. if (isset($var)) { print "This var is set set so I will print."; } // In the next examples we'll use var_dump to output // the return value of isset(). $a = "test"; $b = "anothertest"; var_dump( isset($a) ); // TRUE var_dump( isset ($a, $b) ); // TRUE unset ($a); var_dump( isset ($a) ); // FALSE var_dump( isset ($a, $b) ); // FALSE $foo = NULL; var_dump( isset ($foo) ); // FALSE ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > This also work for elements in arrays: <DIV CLASS="informalexample" ><A NAME="AEN94307" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $a = array ('test' => 1, 'hello' => NULL); var_dump( isset ($a['test']) ); // TRUE var_dump( isset ($a['foo']) ); // FALSE var_dump( isset ($a['hello']) ); // FALSE // The key 'hello' equals NULL so is considered unset // If you want to check for NULL key values then try: var_dump( array_key_exists('hello', $a) ); // TRUE ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > See also <A HREF="function.empty.html" ><B CLASS="function" >empty()</B ></A >, <A HREF="function.unset.html" ><B CLASS="function" >unset()</B ></A >, <A HREF="function.defined.html" ><B CLASS="function" >defined()</B ></A >, <A HREF="function.array-key-exists.html" ><B CLASS="function" >array_key_exists()</B ></A > and the error control <A HREF="language.operators.errorcontrol.html" >@</A > operator. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.is-string.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.print-r.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >is_string</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.variables.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >print_r</TD ></TR ></TABLE ></DIV ></BODY ></HTML >