1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-26 08:42:13 +01:00
Files
archived-doc-ru/reference/array/functions/array-search.xml
2024-12-19 12:22:45 +03:00

131 lines
4.9 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: 768876982f97b3c710c1774511094e259aea297d Maintainer: shein Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.array-search" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>array_search</refname>
<refpurpose>Ищет значение в массиве, и если находит, возвращает ключ первого найденного элемента</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>int</type><type>string</type><type>false</type></type><methodname>array_search</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>needle</parameter> в «стоге сена» <parameter>haystack</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>
Функция <function>array_search</function> будет искать
<emphasis>идентичные</emphasis> элементы в массиве <parameter>haystack</parameter>,
если третьему параметру <parameter>strict</parameter> установили значение &true;.
Поэтому функция также выполнит
<link linkend="language.types">строгое сравнение типа</link>
значения <parameter>needle</parameter> в массиве <parameter>haystack</parameter>,
а индекс объекта функция найдёт, если объект окажется тем же экземпляром.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Функция возвращает ключ значения <parameter>needle</parameter>,
если нашла значение в массиве, иначе возвращает значение &false;.
</para>
<para>
Функция вернёт ключ первого найденного элемента,
если значение <parameter>needle</parameter> встречается в массиве <parameter>haystack</parameter>
больше одного раза. Ключи всех совпадающих значений
умеет находить функция <function>array_keys</function>
при вызове с необязательным аргументом <parameter>filter_value</parameter>.
</para>
&return.falseproblem;
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Пример получения ключа первого найденного элемента функцией <function>array_search</function></title>
<programlisting role="php">
<![CDATA[
<?php
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array); // Значение переменной $key равно 2;
$key = array_search('red', $array); // Значение переменной $key равно 1;
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>array_keys</function></member>
<member><function>array_values</function></member>
<member><function>array_key_exists</function></member>
<member><function>in_array</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
-->