Files
php-doc-ru/reference/array/functions/in-array.xml
Alexey Pyltsyn 402e14208d Arrays: improvements
git-svn-id: https://svn.php.net/repository/phpdoc/ru/trunk@345891 c90b9560-bf6c-de11-be94-00142212c4b1
2018-10-23 09:00:17 +00:00

191 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: 8b5940cadeb4f1c8492f4a7f70743a2be807cf39 Maintainer: shein Status: ready -->
<!-- Reviewed: yes -->
<!-- $Revision$ -->
<refentry xml:id="function.in-array" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>in_array</refname>
<refpurpose>Проверяет, присутствует ли в массиве значение</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>in_array</methodname>
<methodparam><type>mixed</type><parameter>needle</parameter></methodparam>
<methodparam><type>array</type><parameter>haystack</parameter></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>strict</parameter><initializer>&false;</initializer></methodparam>
</methodsynopsis>
<para>
Ищет в <parameter>haystack</parameter> значение <parameter>needle</parameter>.
Если <parameter>strict</parameter> не установлен, то при поиске
будет использовано нестрогое сравнение.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>needle</parameter></term>
<listitem>
<para>
Искомое значение.
</para>
<note>
<para>
Если <parameter>needle</parameter> - строка, сравнение
будет произведено с учетом регистра.
</para>
</note>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>haystack</parameter></term>
<listitem>
<para>
Массив.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>strict</parameter></term>
<listitem>
<para>
Если третий параметр <parameter>strict</parameter> установлен в
&true;, тогда функция <function>in_array</function>
также проверит соответствие <link linkend="language.types">типов</link>
параметра <parameter>needle</parameter> и соответствующего
значения массива <parameter>haystack</parameter>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Возвращает &true;, если <parameter>needle</parameter> был найден
в массиве, и &false; в противном случае.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Пример использования <function>in_array</function></title>
<programlisting role="php">
<![CDATA[
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Нашел Irix";
}
if (in_array("mac", $os)) {
echo "Нашел mac";
}
?>
]]>
</programlisting>
<para>
Второго совпадения не будет, потому что <function>in_array</function>
регистрозависима, таким образом, программа выведет:
</para>
<screen>
<![CDATA[
Нашел Irix
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Пример использования <function>in_array</function> с параметром strict</title>
<programlisting role="php">
<![CDATA[
<?php
$a = array('1.10', 12.4, 1.13);
if (in_array('12.4', $a, true)) {
echo "'12.4' найдено со строгой проверкой\n";
}
if (in_array(1.13, $a, true)) {
echo "1.13 найдено со строгой проверкой\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
1.13 найдено со строгой проверкой
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Пример использования <function>in_array</function> с массивом в качестве параметра needle</title>
<programlisting role="php">
<![CDATA[
<?php
$a = array(array('p', 'h'), array('p', 'r'), 'o');
if (in_array(array('p', 'h'), $a)) {
echo "'ph' найдено\n";
}
if (in_array(array('f', 'i'), $a)) {
echo "'fi' найдено\n";
}
if (in_array('o', $a)) {
echo "'o' найдено\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
'ph' найдено
'o' найдено
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>array_search</function></member>
<member><function>isset</function></member>
<member><function>array_key_exists</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
-->