⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.isset.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Determine whether a variable is set</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.is-unicode.html">is_unicode</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.print-r.html">print_r</a></div> <div class="up"><a href="ref.var.html">Variable handling Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.isset" class="refentry"> <div class="refnamediv">  <h1 class="refname">isset</h1>  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">isset</span> &mdash; <span class="dc-title">Determine whether a variable is set</span></p> </div>  <div class="refsect1 description"> <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">bool</span> <span class="methodname"><b><b>isset</b></b></span>    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$var</tt></span>   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$var</tt></span>   [, <span class="methodparam"> <tt class="parameter">$...</tt></span>  ]] )</div>  <p class="para rdfs-comment">   Determine whether a variable is set.  </p>  <p class="para">   If a variable has been unset with <a href="function.unset.html" class="function">unset()</a>, it will no   longer be set. <b>isset()</b> will return <b><tt>FALSE</tt></b> if testing a   variable that has been set to <b><tt>NULL</tt></b>. Also note that a <b><tt>NULL</tt></b> byte   (<i>&quot;\0&quot;</i>) is not equivalent to the PHP <b><tt>NULL</tt></b> constant.  </p>  <p class="para">   If multiple parameters are supplied then <b>isset()</b> will   return <b><tt>TRUE</tt></b> only if all of the parameters are set. Evaluation goes from   left to right and stops as soon as an unset variable is encountered.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">var</tt></i></span>     <dd>      <p class="para">       The variable to be checked.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">var</tt></i></span>     <dd>      <p class="para">       Another variable ..      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">...</tt></i></span>     <dd>      <p class="para">      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   Returns <b><tt>TRUE</tt></b> if <i><tt class="parameter">var</tt></i> exists; <b><tt>FALSE</tt></b> otherwise.  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>isset()</b> Examples</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$var&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;This&nbsp;will&nbsp;evaluate&nbsp;to&nbsp;TRUE&nbsp;so&nbsp;the&nbsp;text&nbsp;will&nbsp;be&nbsp;printed.<br /></span><span style="color: #007700">if&nbsp;(isset(</span><span style="color: #0000BB">$var</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"This&nbsp;var&nbsp;is&nbsp;set&nbsp;so&nbsp;I&nbsp;will&nbsp;print."</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;In&nbsp;the&nbsp;next&nbsp;examples&nbsp;we'll&nbsp;use&nbsp;var_dump&nbsp;to&nbsp;output<br />//&nbsp;the&nbsp;return&nbsp;value&nbsp;of&nbsp;isset().<br /><br /></span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$b&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"anothertest"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;TRUE<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;TRUE<br /><br /></span><span style="color: #007700">unset&nbsp;(</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;FALSE<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;FALSE<br /><br /></span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;FALSE<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p>  <p class="para">   This also work for elements in arrays:   <div class="informalexample">    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$a&nbsp;</span><span style="color: #007700">=&nbsp;array&nbsp;(</span><span style="color: #DD0000">'test'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'hello'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">[</span><span style="color: #DD0000">'test'</span><span style="color: #007700">]));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;TRUE<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">[</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">]));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;FALSE<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">[</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">]));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;FALSE<br /><br />//&nbsp;The&nbsp;key&nbsp;'hello'&nbsp;equals&nbsp;NULL&nbsp;so&nbsp;is&nbsp;considered&nbsp;unset<br />//&nbsp;If&nbsp;you&nbsp;want&nbsp;to&nbsp;check&nbsp;for&nbsp;NULL&nbsp;key&nbsp;values&nbsp;then&nbsp;try:&nbsp;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">array_key_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$a</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;TRUE<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p> </div> <div class="refsect1 notes">  <h3 class="title">Notes</h3>  <div class="warning"><b class="warning">Warning</b>   <p class="para">    <b>isset()</b> only works with variables as passing anything    else will result in a parse error.  For checking if     <a href="language.constants.html" class="link">constants</a> are set use the     <a href="function.defined.html" class="function">defined()</a> function.   </p>  </div>  <blockquote><p><b class="note">Note</b>: <span class="simpara">Because this is a language construct and not a function, it cannot be called using <a href="functions.variable-functions.html" class="link">variable functions</a></span></p></blockquote> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.empty.html" class="function" rel="rdfs-seeAlso">empty()</a></li>    <li class="member"><a href="function.unset.html" class="function" rel="rdfs-seeAlso">unset()</a></li>    <li class="member"><a href="function.defined.html" class="function" rel="rdfs-seeAlso">defined()</a></li>    <li class="member"><a href="types.comparisons.html" class="link">the type comparison tables</a></li>    <li class="member"><a href="function.array-key-exists.html" class="function" rel="rdfs-seeAlso">array_key_exists()</a></li>    <li class="member"><a href="function.is-null.html" class="function" rel="rdfs-seeAlso">is_null()</a></li>    <li class="member">the error control <a href="language.operators.errorcontrol.html" class="link">@</a> operator</li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.is-unicode.html">is_unicode</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.print-r.html">print_r</a></div> <div class="up"><a href="ref.var.html">Variable handling Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -