Files
php-doc-ru/reference/array/functions/array-key-exists.xml

181 lines
5.6 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: 89fe795cc8bcf1b5ff9eb894bff51f006db66a65 Maintainer: shein Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.array-key-exists" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>array_key_exists</refname>
<refpurpose>Проверяет, существует ли в массиве заданный ключ или индекс</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>array_key_exists</methodname>
<methodparam><type class="union"><type>string</type><type>int</type><type>float</type><type>bool</type><type>resource</type><type>null</type></type><parameter>key</parameter></methodparam>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<para>
Функция <function>array_key_exists</function> возвращает &true;, если
заданный ключ (<parameter>key</parameter>) содержится в массиве.
В параметр <parameter>key</parameter> разрешено передавать значение,
которое допустимо в качестве индекса массива.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>key</parameter></term>
<listitem>
<para>
Проверяемое значение.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>array</parameter></term>
<listitem>
<para>
Массив с проверяемыми ключами.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
<note>
<para>
Функция <function>array_key_exists</function> ищет ключи только на первом уровне массива.
Внутренние ключи в многомерных массивах найдены не будут.
</para>
</note>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
Параметр <parameter>key</parameter> теперь принимает в качестве аргументов значения
<parameter>bool</parameter>, <parameter>float</parameter>, <parameter>int</parameter>,
<parameter>null</parameter>, <parameter>resource</parameter>
и <parameter>string</parameter>.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Пример использования функции <function>array_key_exists</function></title>
<programlisting role="php">
<![CDATA[
<?php
$search_array = array('first' => 1, 'second' => 4);
if (array_key_exists('first', $search_array)) {
echo "Массив содержит элемент «first».";
}
?>
]]>
</programlisting>
</example>
</para>
<example>
<title>
Пример использования функции <function>array_key_exists</function> с языковой конструкцией <function>isset</function>
</title>
<para>
Конструкция языка <function>isset</function> не возвращает &true; для ключей массива,
которые ассоциированы со значением &null;,
а функция <function>array_key_exists</function> — возвращает.
</para>
<programlisting role="php">
<![CDATA[
<?php
$search_array = array('first' => null, 'second' => 4);
// Возвращает false
isset($search_array['first']);
// Возвращает true
array_key_exists('first', $search_array);
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<para>
По причинам обратной совместимости функция <function>array_key_exists</function>
возвращает &true;, если ключ (<parameter>key</parameter>) — это свойство
объекта (<type>object</type>), переданного в качестве параметра <parameter>array</parameter>.
Поведение устарело в PHP 7.4.0 и удалено в PHP 8.0.0.
</para>
<para>
Проверить, содержит ли объект заданное свойство, можно функцией
<function>property_exists</function>.
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>isset</function></member>
<member><function>array_keys</function></member>
<member><function>in_array</function></member>
<member><function>property_exists</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
-->