1
0
mirror of https://github.com/php/doc-ru.git synced 2026-04-23 07:18:12 +02:00
Files
archived-doc-ru/reference/var/functions/is-numeric.xml
T
2024-01-22 11:04:02 +03:00

219 lines
5.3 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 0817d5b2835f8a47314823338d983fa2c5005dfc Maintainer: rjhdby Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.is-numeric" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>is_numeric</refname>
<refpurpose>
Проверяет, содержит ли переменная число или числовую строку
</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>
Определяет, представляет ли собой переменная число
или <link linkend="language.types.numeric-strings">строку, содержащую число</link>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>value</parameter></term>
<listitem>
<para>
Проверяемая переменная.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Возвращает &true;, если значение <parameter>value</parameter> — число или
<link linkend="language.types.numeric-strings">строка, содержащая число</link>,
иначе &false;.
</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>
Строки, состоящие из чисел и заканчивающиеся пробелом (<literal>«42 »</literal>), теперь будут
возвращать &true;. Раньше вместо этого возвращалось &false;.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Примеры использования функции <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) . " число", PHP_EOL;
} else {
echo var_export($element, true) . " НЕ число", PHP_EOL;
}
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
42 - число
1337 - число
1337 - число
1337 - число
1337 - число
1337.0 - число
'0x539' - НЕ число
'02471' - число
'0b10100111001' - НЕ число
'1337e0' - число
'not numeric' - НЕ число
array (
) - НЕ число
9.1 - число
NULL - НЕ число
'' - НЕ число
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Пример использования функции <function>is_numeric</function> с пробелом</title>
<programlisting role="php">
<![CDATA[
<?php
$tests = [
" 42",
"42 ",
"\u{A0}9001", // Неразрывный пробел
"9001\u{A0}", // Неразрывный пробел
];
foreach ($tests as $element) {
if (is_numeric($element)) {
echo var_export($element, true) . " — число", PHP_EOL;
} else {
echo var_export($element, true) . " — НЕ число", PHP_EOL;
}
}
?>
]]>
</programlisting>
&example.outputs.8;
<screen>
<![CDATA[
' 42' — число
'42 ' — число
' 9001' — НЕ число
'9001 ' — НЕ число
]]>
</screen>
&example.outputs.7;
<screen>
<![CDATA[
' 42' — число
'42 ' — НЕ число
' 9001' — НЕ число
'9001 ' — НЕ число
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><link linkend="language.types.numeric-strings">Строки, содержащие числа</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
-->