Files
php-doc-ru/reference/array/functions/array-search.xml
Mikhail Alferov 01fd1e80af Update reference/array/functions to En (#1068)
* Update book.xml to en

* Update array-combine.xml to en

* Update array-diff.xml to en

* Update array-fill.xml to en

* Update array-is-list.xml to en

* Update array-map.xml to en

* Update array-merge.xml to en

* Update array-multisort.xml to en

* Update array-pad.xml to en

* Update array-search.xml to en

* Update array-splice.xml to en

* Update array-udiff-uassoc.xml to en

* Update array.xml to en

* Update count.xml to en

* Update current.xml to en

* Update each.xml to en

* Update in-array.xml to en

* Update list.xml to en

* Update next.xml to en

* Update prev.xml to en

* Update usort.xml to en
2025-05-09 09:05:53 +03:00

134 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: 2e60c5134e7a847c99f81eb3f7ecee1f5efeeace 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;
print_r($key);
$key = array_search('red', $array); // Значение переменной $key равно 1;
print_r($key);
?>
]]>
</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
-->