2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 06:30:45 +00:00
|
|
|
<!-- $Revision$ -->
|
2007-06-20 22:25:43 +00:00
|
|
|
<refentry xml:id="function.array-search" xmlns="http://docbook.org/ns/docbook">
|
2006-10-31 11:24:02 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>array_search</refname>
|
2016-07-22 16:33:15 +00:00
|
|
|
<refpurpose>Searches the array for a given value and returns the first corresponding key if successful</refpurpose>
|
2006-10-31 11:24:02 +00:00
|
|
|
</refnamediv>
|
2007-12-30 19:17:05 +00:00
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2006-10-31 11:24:02 +00:00
|
|
|
<methodsynopsis>
|
2020-12-04 00:35:15 +00:00
|
|
|
<type class="union"><type>int</type><type>string</type><type>false</type></type><methodname>array_search</methodname>
|
2006-10-31 11:24:02 +00:00
|
|
|
<methodparam><type>mixed</type><parameter>needle</parameter></methodparam>
|
|
|
|
<methodparam><type>array</type><parameter>haystack</parameter></methodparam>
|
2018-01-25 19:11:34 +00:00
|
|
|
<methodparam choice="opt"><type>bool</type><parameter>strict</parameter><initializer>&false;</initializer></methodparam>
|
2006-10-31 11:24:02 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
2019-04-01 19:16:35 +00:00
|
|
|
Searches for <parameter>needle</parameter> in <parameter>haystack</parameter>.
|
2006-10-31 11:24:02 +00:00
|
|
|
</para>
|
2007-12-30 19:17:05 +00:00
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>needle</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The searched value.
|
|
|
|
</para>
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
If <parameter>needle</parameter> is a string, the comparison is done
|
|
|
|
in a case-sensitive manner.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>haystack</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The array.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>strict</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If the third parameter <parameter>strict</parameter> is set to &true;
|
2010-04-09 14:04:21 +00:00
|
|
|
then the <function>array_search</function> function will search for
|
|
|
|
<emphasis>identical</emphasis> elements in the
|
2017-01-02 12:28:48 +00:00
|
|
|
<parameter>haystack</parameter>. This means it will also perform a
|
|
|
|
<link linkend="language.types">strict type comparison</link> of the
|
2010-04-09 14:04:21 +00:00
|
|
|
<parameter>needle</parameter> in the <parameter>haystack</parameter>,
|
|
|
|
and objects must be the same instance.
|
2007-12-30 19:17:05 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
2007-12-30 19:17:05 +00:00
|
|
|
Returns the key for <parameter>needle</parameter> if it is found in the
|
|
|
|
array, &false; otherwise.
|
2006-10-31 11:24:02 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2007-12-30 19:17:05 +00:00
|
|
|
If <parameter>needle</parameter> is found in <parameter>haystack</parameter>
|
|
|
|
more than once, the first matching key is returned. To return the keys for
|
|
|
|
all matching values, use <function>array_keys</function> with the optional
|
2006-10-31 11:24:02 +00:00
|
|
|
<parameter>search_value</parameter> parameter instead.
|
|
|
|
</para>
|
2007-12-30 19:17:05 +00:00
|
|
|
&return.falseproblem;
|
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>array_search</function> example</title>
|
|
|
|
<programlisting role="php">
|
2003-12-15 19:16:05 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
2004-01-01 06:44:47 +00:00
|
|
|
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
|
2003-12-15 19:16:05 +00:00
|
|
|
|
2004-01-01 06:44:47 +00:00
|
|
|
$key = array_search('green', $array); // $key = 2;
|
|
|
|
$key = array_search('red', $array); // $key = 1;
|
2003-12-15 19:16:05 +00:00
|
|
|
?>
|
|
|
|
]]>
|
2006-10-31 11:24:02 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
2007-12-30 19:17:05 +00:00
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
2007-12-30 19:17:05 +00:00
|
|
|
<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>
|
2006-10-31 11:24:02 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2002-04-15 00:12:54 +00:00
|
|
|
<!-- 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
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2002-04-15 00:12:54 +00:00
|
|
|
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
|
|
|
|
-->
|