Files
php-doc-ru/reference/array/functions/in-array.xml
2005-03-06 16:44:36 +00:00

158 lines
4.5 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: 1.12 Maintainer: sveta Status: ready -->
<!-- $Revision: 1.2 $ -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.56 -->
<refentry id="function.in-array">
<refnamediv>
<refname>in_array</refname>
<refpurpose>Проверить, присутствует ли в массиве значение</refpurpose>
</refnamediv>
<refsect1>
<title>Описание</title>
<methodsynopsis>
<type>bool</type><methodname>in_array</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> и возвращает &true;
в случае удачи, &false; в противном случае.
</para>
<para>
Если третий параметр <parameter>strict</parameter> установлен в
&true; тогда функция <function>in_array</function>
также проверит соответствие <link linkend="language.types">types</link>
параметра <parameter>needle</parameter> и соответствующего значения массива
<parameter>haystack</parameter>.
</para>
<note>
<para>
Если <parameter>needle</parameter> - строка, сравнение будет регистрозависмым.
</para>
</note>
<note>
<para>
В PHP версий, более ранних, чем 4.2.0 параметр <parameter>needle</parameter>
не может быть массивом.
</para>
</note>
<para>
<example>
<title>Пример использования <function>in_array</function></title>
<programlisting role="php">
<![CDATA[
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
]]>
</programlisting>
<para>
Второго совпадения не будет, потому что <function>in_array</function>
регистрозависима, таким образом, программа выведет:
</para>
<screen>
<![CDATA[
Got Irix
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Пример использования <function>in_array</function> с параметром strict</title>
<programlisting role="php">
<![CDATA[
<?php
$a = array('1.10', 12.4, 1.13);
if (in_array('12.4', $a, true)) {
echo "'12.4' found with strict check
";
}
if (in_array(1.13, $a, true)) {
echo "1.13 found with strict check
";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
1.13 found with strict check
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Пример использования <function>in_array</function> с массивом в качестве параметра needle</title>
<programlisting role="php">
<![CDATA[
<?php
$a = array(array('p', 'h'), array('p', 'r'), 'o');
if (in_array(array('p', 'h'), $a)) {
echo "'ph' найдено
";
}
if (in_array(array('f', 'i'), $a)) {
echo "'fi' найдено
";
}
if (in_array('o', $a)) {
echo "'o' найдено
";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
'ph' найдено
'o' найдено
]]>
</screen>
</example>
</para>
<para>
См. также <function>array_search</function>,
<function>array_key_exists</function> и
<function>isset</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
-->