mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-23 22:52:12 +01:00
215 lines
4.8 KiB
XML
215 lines
4.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 0817d5b2835f8a47314823338d983fa2c5005dfc Maintainer: leonardolara Status: ready -->
|
|
<refentry xml:id="function.is-numeric" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>is_numeric</refname>
|
|
<refpurpose>
|
|
Verifica se uma variável é um número ou uma string numérica
|
|
</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>is_numeric</methodname>
|
|
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Determina se a variável fornecida é um número ou uma
|
|
<link linkend="language.types.numeric-strings">string numérica</link>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>value</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
A variável a ser avaliada.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retorna &true; se <parameter>value</parameter> for um número ou uma
|
|
<link linkend="language.types.numeric-strings">string numérica</link>,
|
|
&false; caso contrário.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.0.0</entry>
|
|
<entry>
|
|
String numéricas terminando com espaços (<literal>"42 "</literal>) agora
|
|
retornam &true;. Anteriormente, &false; era retornado.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemplos de <function>is_numeric</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$tests = array(
|
|
"42",
|
|
1337,
|
|
0x539,
|
|
02471,
|
|
0b10100111001,
|
|
1337e0,
|
|
"0x539",
|
|
"02471",
|
|
"0b10100111001",
|
|
"1337e0",
|
|
"not numeric",
|
|
array(),
|
|
9.1,
|
|
null,
|
|
'',
|
|
);
|
|
|
|
foreach ($tests as $element) {
|
|
if (is_numeric($element)) {
|
|
echo var_export($element, true) . " é numérico", PHP_EOL;
|
|
} else {
|
|
echo var_export($element, true) . " NÃO é numérico", PHP_EOL;
|
|
}
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
'42' é numérico
|
|
1337 é numérico
|
|
1337 é numérico
|
|
1337 é numérico
|
|
1337 é numérico
|
|
1337.0 é numérico
|
|
'0x539' NÃO é numérico
|
|
'02471' é numérico
|
|
'0b10100111001' NÃO é numérico
|
|
'1337e0' é numérico
|
|
'not numeric' NÃO é numérico
|
|
array (
|
|
) NÃO é numérico
|
|
9.1 é numérico
|
|
NULL NÃO é numérico
|
|
'' NÃO é numérico
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
|
|
<para>
|
|
<example>
|
|
<title><function>is_numeric</function> com espaço em branco</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$tests = [
|
|
" 42",
|
|
"42 ",
|
|
"\u{A0}9001", // caractere de espaço sem quebra
|
|
"9001\u{A0}", // caractere de espaço sem quebra
|
|
];
|
|
|
|
foreach ($tests as $element) {
|
|
if (is_numeric($element)) {
|
|
echo var_export($element, true) . " é numérico", PHP_EOL;
|
|
} else {
|
|
echo var_export($element, true) . " NÃO é numérico", PHP_EOL;
|
|
}
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.8;
|
|
<screen>
|
|
<![CDATA[
|
|
' 42' é numérico
|
|
'42 ' é numérico
|
|
' 9001' NÃO é numérico
|
|
'9001 ' NÃO é numérico
|
|
]]>
|
|
</screen>
|
|
&example.outputs.7;
|
|
<screen>
|
|
<![CDATA[
|
|
' 42' é numérico
|
|
'42 ' NÃO é numérico
|
|
' 9001' NÃO é numérico
|
|
'9001 ' NÃO é numérico
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><link linkend="language.types.numeric-strings">Strings numéricas</link></member>
|
|
<member><function>ctype_digit</function></member>
|
|
<member><function>is_bool</function></member>
|
|
<member><function>is_null</function></member>
|
|
<member><function>is_float</function></member>
|
|
<member><function>is_int</function></member>
|
|
<member><function>is_string</function></member>
|
|
<member><function>is_object</function></member>
|
|
<member><function>is_array</function></member>
|
|
<member><function>filter_var</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|