<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = 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 => 'es',
  ),
  'this' => 
  array (
    0 => 'function.is-numeric.php',
    1 => 'is_numeric',
    2 => 'Determina si una variable es un n&uacute;mero o una cadena num&eacute;rica',
  ),
  'up' => 
  array (
    0 => 'ref.var.php',
    1 => 'Funciones de manejo de variables',
  ),
  'prev' => 
  array (
    0 => 'function.is-null.php',
    1 => 'is_null',
  ),
  'next' => 
  array (
    0 => 'function.is-object.php',
    1 => 'is_object',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'es',
    'path' => 'reference/var/functions/is-numeric.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.is-numeric" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">is_numeric</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">is_numeric</span> &mdash; <span class="dc-title">
   Determina si una variable es un número o una cadena numérica
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.is-numeric-description">
  <h3 class="title">Descripción</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>is_numeric</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Determina si la variable dada es un número o una
   <a href="language.types.numeric-strings.php" class="link">cadena numérica</a>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.is-numeric-parameters">
  <h3 class="title">Parámetros</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       La variable a evaluar.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.is-numeric-returnvalues">
  <h3 class="title">Valores devueltos</h3>
  <p class="para">
   Retorna <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> si <code class="parameter">value</code> es un número o una
   <a href="language.types.numeric-strings.php" class="link">cadena numérica</a>,
   <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> en caso contrario.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.is-numeric-changelog">
  <h3 class="title">Historial de cambios</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versión</th>
      <th>Descripción</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       Las cadenas numéricas que terminan con caracteres de espaciado en blanco
       (<code class="literal">&quot;42 &quot;</code>) retornarán ahora <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>.
       Anteriormente, se retornaba <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> en su lugar.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.is-numeric-examples">
  <h3 class="title">Ejemplos</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Ejemplo #1 Ejemplo con <span class="function"><strong>is_numeric()</strong></span></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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: #0000BB">0x539</span><span style="color: #007700">,<br />    </span><span style="color: #0000BB">02471</span><span style="color: #007700">,<br />    </span><span style="color: #0000BB">0b10100111001</span><span style="color: #007700">,<br />    </span><span style="color: #0000BB">1337e0</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">"0x539"</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">"02471"</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">"0b10100111001"</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">"1337e0"</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</span><span style="color: #007700">,<br />    </span><span style="color: #0000BB">null</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />);<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 />    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 />        echo </span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$element</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">) . </span><span style="color: #DD0000">" es numérico"</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />    } else {<br />        echo </span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$element</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">) . </span><span style="color: #DD0000">" NO es numérico"</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">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>El ejemplo anterior mostrará:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">&#039;42&#039; es numérico
1337 es numérico
1337 es numérico
1337 es numérico
1337 es numérico
1337.0 es numérico
&#039;0x539&#039; NO es numérico
&#039;02471&#039; es numérico
&#039;0b10100111001&#039; NO es numérico
&#039;1337e0&#039; es numérico
&#039;not numeric&#039; NO es numérico
array (
) NO es numérico
9.1 es numérico
NULL NO es numérico
&#039;&#039; NO es numérico</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Ejemplo #2 <span class="function"><strong>is_numeric()</strong></span> con caracteres de espaciado en blanco</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$tests </span><span style="color: #007700">= [<br />    </span><span style="color: #DD0000">" 42"</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">"42 "</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">"\u{A0}9001"</span><span style="color: #007700">, </span><span style="color: #FF8000">// non-breaking space<br />    </span><span style="color: #DD0000">"9001\u{A0}"</span><span style="color: #007700">, </span><span style="color: #FF8000">// non-breaking space<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 />    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 />        echo </span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$element</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">) . </span><span style="color: #DD0000">" is numeric"</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />    } else {<br />        echo </span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$element</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">) . </span><span style="color: #DD0000">" 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">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Resultado del ejemplo anterior en PHP 8:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">&#039; 42&#039; is numeric
&#039;42 &#039; is numeric
&#039; 9001&#039; is NOT numeric
&#039;9001 &#039; is NOT numeric</pre>
</div>
    </div>
    <div class="example-contents"><p>Resultado del ejemplo anterior en PHP 7:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">&#039; 42&#039; is numeric
&#039;42 &#039; is NOT numeric
&#039; 9001&#039; is NOT numeric
&#039;9001 &#039; is NOT numeric</pre>
</div>
   </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.is-numeric-seealso">
  <h3 class="title">Ver también</h3>
  <p class="para">
   <ul class="simplelist">
    <li><a href="language.types.numeric-strings.php" class="link">Las cadenas numéricas</a></li>
    <li><span class="function"><a href="function.ctype-digit.php" class="function" rel="rdfs-seeAlso">ctype_digit()</a> - Chequear posibles caracteres num&eacute;ricos</span></li>
    <li><span class="function"><a href="function.is-bool.php" class="function" rel="rdfs-seeAlso">is_bool()</a> - Determina si una variable es un bool</span></li>
    <li><span class="function"><a href="function.is-null.php" class="function" rel="rdfs-seeAlso">is_null()</a> - Indica si una variable es null</span></li>
    <li><span class="function"><a href="function.is-float.php" class="function" rel="rdfs-seeAlso">is_float()</a> - Determina si una variable es de tipo float</span></li>
    <li><span class="function"><a href="function.is-int.php" class="function" rel="rdfs-seeAlso">is_int()</a> - Determina si una variable es de tipo integer</span></li>
    <li><span class="function"><a href="function.is-string.php" class="function" rel="rdfs-seeAlso">is_string()</a> - Determina si una variable es de tipo string</span></li>
    <li><span class="function"><a href="function.is-object.php" class="function" rel="rdfs-seeAlso">is_object()</a> - Determina si una variable es de tipo objeto</span></li>
    <li><span class="function"><a href="function.is-array.php" class="function" rel="rdfs-seeAlso">is_array()</a> - Determina si una variable es un array</span></li>
    <li><span class="function"><a href="function.filter-var.php" class="function" rel="rdfs-seeAlso">filter_var()</a> - Filtra una variable con el filtro que se indique</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>