downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the Git repository for this website on git.php.net.

Source of: /manual/fa/function.is-numeric.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.var.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'fa',
  ),
 
'this' =>
  array (
   
0 => 'function.is-numeric.php',
   
1 => 'is_numeric',
  ),
 
'up' =>
  array (
   
0 => 'ref.var.php',
   
1 => 'Variable handling Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.is-null.php',
   
1 => 'is_null',
  ),
 
'next' =>
  array (
   
0 => 'function.is-object.php',
   
1 => 'is_object',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<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> &mdash; <span class="dc-title">
   Finds whether a variable is a number or a numeric string
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.is-numeric-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><b>is_numeric</b></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.php#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" id="refsect1-function.is-numeric-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" id="refsect1-function.is-numeric-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" id="refsect1-function.is-numeric-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-4323">
    <p><b>Example #1 <span class="function"><b>is_numeric()</b></span> examples</b></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$tests&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"42"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">1337</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"1e4"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"not&nbsp;numeric"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Array(),&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">9.1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">);<br /><br />foreach&nbsp;(</span><span style="color: #0000BB">$tests&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$element</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">is_numeric</span><span style="color: #007700">(</span><span style="color: #0000BB">$element</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"'</span><span style="color: #007700">{</span><span style="color: #0000BB">$element</span><span style="color: #007700">}</span><span style="color: #DD0000">'&nbsp;is&nbsp;numeric"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"'</span><span style="color: #007700">{</span><span style="color: #0000BB">$element</span><span style="color: #007700">}</span><span style="color: #DD0000">'&nbsp;is&nbsp;NOT&nbsp;numeric"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&#039;42&#039; is numeric
&#039;1337&#039; is numeric
&#039;1e4&#039; is numeric
&#039;not numeric&#039; is NOT numeric
&#039;Array&#039; is NOT numeric
&#039;9.1&#039; is numeric
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.is-numeric-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.ctype-digit.php" class="function" rel="rdfs-seeAlso">ctype_digit()</a> - Check for numeric character(s)</span></li>
    <li class="member"><span class="function"><a href="function.is-bool.php" class="function" rel="rdfs-seeAlso">is_bool()</a> - Finds out whether a variable is a boolean</span></li>
    <li class="member"><span class="function"><a href="function.is-null.php" class="function" rel="rdfs-seeAlso">is_null()</a> - Finds whether a variable is NULL</span></li>
    <li class="member"><span class="function"><a href="function.is-float.php" class="function" rel="rdfs-seeAlso">is_float()</a> - Finds whether the type of a variable is float</span></li>
    <li class="member"><span class="function"><a href="function.is-int.php" class="function" rel="rdfs-seeAlso">is_int()</a> - Find whether the type of a variable is integer</span></li>
    <li class="member"><span class="function"><a href="function.is-string.php" class="function" rel="rdfs-seeAlso">is_string()</a> - Find whether the type of a variable is string</span></li>
    <li class="member"><span class="function"><a href="function.is-object.php" class="function" rel="rdfs-seeAlso">is_object()</a> - Finds whether a variable is an object</span></li>
    <li class="member"><span class="function"><a href="function.is-array.php" class="function" rel="rdfs-seeAlso">is_array()</a> - Finds whether a variable is an array</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites