📄 function.is-numeric.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Finds whether a variable is a number or a numeric string</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-null.html">is_null</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.is-object.html">is_object</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.is-numeric" class="refentry"> <div class="refnamediv"> <h1 class="refname">is_numeric</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">is_numeric</span> — <span class="dc-title"> Finds whether a variable is a number or a numeric string </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>is_numeric</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> )</div> <p class="para rdfs-comment"> Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus <i>+0123.45e6</i> is a valid numeric value. Hexadecimal notation (<i>0xFF</i>) is allowed too but only without sign, decimal and exponential part. </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 being evaluated. </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> is a number or a numeric string, <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>is_numeric()</b> examples</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$tests </span><span style="color: #007700">= Array(<br /> </span><span style="color: #DD0000">"42"</span><span style="color: #007700">, <br /> </span><span style="color: #0000BB">1337</span><span style="color: #007700">, <br /> </span><span style="color: #DD0000">"1e4"</span><span style="color: #007700">, <br /> </span><span style="color: #DD0000">"not numeric"</span><span style="color: #007700">, <br /> Array(), <br /> </span><span style="color: #0000BB">9.1<br /> </span><span style="color: #007700">);<br /><br />foreach(</span><span style="color: #0000BB">$tests </span><span style="color: #007700">as </span><span style="color: #0000BB">$element</span><span style="color: #007700">)<br />{<br /> if(</span><span style="color: #0000BB">is_numeric</span><span style="color: #007700">(</span><span style="color: #0000BB">$element</span><span style="color: #007700">))<br /> {<br /> echo </span><span style="color: #DD0000">"'{$element}' is numeric"</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /> }<br /> else<br /> {<br /> echo </span><span style="color: #DD0000">"'{$element}' is NOT numeric"</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /> }<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.ctype-digit.html" class="function" rel="rdfs-seeAlso">ctype_digit()</a></li> <li class="member"><a href="function.is-bool.html" class="function" rel="rdfs-seeAlso">is_bool()</a></li> <li class="member"><a href="function.is-null.html" class="function" rel="rdfs-seeAlso">is_null()</a></li> <li class="member"><a href="function.is-float.html" class="function" rel="rdfs-seeAlso">is_float()</a></li> <li class="member"><a href="function.is-int.html" class="function" rel="rdfs-seeAlso">is_int()</a></li> <li class="member"><a href="function.is-string.html" class="function" rel="rdfs-seeAlso">is_string()</a></li> <li class="member"><a href="function.is-object.html" class="function" rel="rdfs-seeAlso">is_object()</a></li> <li class="member"><a href="function.is-array.html" class="function" rel="rdfs-seeAlso">is_array()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.is-null.html">is_null</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.is-object.html">is_object</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 + -