1
0
mirror of https://github.com/php/doc-ja.git synced 2026-03-25 15:42:08 +01:00
Files
archived-doc-ja/reference/array/functions/array-search.xml
TAKAGI Masahiro cdfe3e4bbb sync with en.
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@222583 c90b9560-bf6c-de11-be94-00142212c4b1
2006-10-31 13:44:12 +00:00

96 lines
3.1 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.8 $ -->
<!-- EN-Revision: 1.10 Maintainer: hirokawa Status: ready -->
<!-- CREDITS: shimooka -->
<refentry id="function.array-search">
<refnamediv>
<refname>array_search</refname>
<refpurpose>
指定した値を配列で検索し、見つかった場合に対応するキーを返す
</refpurpose>
</refnamediv>
<refsect1>
<title>説明</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>
<parameter>haystack</parameter> において
<parameter>needle</parameter> を検索し、
配列中に見付かった場合にそのキーを返します。そうでない場合に&false;を返します。
</para>
<note>
<para>
もし <parameter>needle</parameter> が文字列の場合、
大文字小文字を区別して比較が行われます。
</para>
</note>
<note>
<para>
PHP 4.2.0 以前では、<function>array_search</function> は、
失敗した場合に &false; ではなく &null; を返します。
</para>
</note>
<para>
オプションの3番目のパラメータ <parameter>strict</parameter>
&true; が指定された場合、<function>array_search</function>
<parameter>haystack</parameter> の中で
<parameter>needle</parameter> の型に一致するかどうかも確認します。
</para>
<para>
もし <parameter>haystack</parameter> に 1 つ以上の
<parameter>needle</parameter> に見つかった場合、
最初にマッチしたキーが返されます。
全てのマッチした値に対するキーを返すためには、代わりに
<function>array_keys</function> にパラメータ
<parameter>search_value</parameter> を付けて使用してください。
</para>
<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>
&return.falseproblem;
<para>
<function>array_keys</function>
<function>array_values</function>
<function>array_key_exists</function> および
<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
-->