<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
  <refentry id="function.array-search">
   <refnamediv>
    <refname>array_search</refname>
    <refpurpose>
     Searches the array for a given value and returns the
     corresponding key if successful
    </refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>mixed</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></methodparam>
     </methodsynopsis>
    <para>
     Searches <parameter>haystack</parameter> for
     <parameter>needle</parameter> and returns the key if it is found in
     the array, &false; otherwise.
    </para>
    <note>
     <para>
      If <parameter>needle</parameter> is a string, the comparison is done
      in a case-sensitive manner.
     </para>
    </note>
    <note>
     <para>
      Prior to PHP 4.2.0, <function>array_search</function> returns
      <constant>NULL</constant> on failure instead of &false;.
     </para>
    </note>
    <para>
     If the optional third parameter <parameter>strict</parameter> is set to
     &true; then the <function>array_search</function>
     will also check the types of the <parameter>needle</parameter>
     in the <parameter>haystack</parameter>.
    </para>
    <para>
     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
     <parameter>search_value</parameter> parameter instead.
    </para>
    <para>
     <example>
      <title><function>array_search</function> example</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>
    &return.falseproblem;
    <para>
     See also <function>array_keys</function>,
     <function>array_values</function>,
     <function>array_key_exists</function>, and
     <function>in_array</function>.
    </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:"../../../../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
-->