1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-25 16:22:18 +01:00
Files
archived-doc-ru/reference/array/functions/array-unique.xml
Alexey Pyltsyn ef460a3ab1 Array Functions: improvements
git-svn-id: https://svn.php.net/repository/phpdoc/ru/trunk@344296 c90b9560-bf6c-de11-be94-00142212c4b1
2018-02-19 16:05:23 +00:00

214 lines
6.3 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: b210b056cdbfb8e12ca9c5df8f64e546fb5def57 Maintainer: shein Status: ready -->
<!-- Reviewed: yes -->
<!-- $Revision$ -->
<refentry xml:id="function.array-unique" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>array_unique</refname>
<refpurpose>Убирает повторяющиеся значения из массива</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>array_unique</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>sort_flags</parameter><initializer>SORT_STRING</initializer></methodparam>
</methodsynopsis>
<para>
Принимает входной <parameter>array</parameter> и возвращает новый массив
без повторяющихся значений.
</para>
<para>
Обратите внимание, что ключи сохранятся. Если в соответствии с заданными
<parameter>sort_flags</parameter> несколько элементов определяются как
идентичные, то будут сохранены ключ и значение первого такого элемента.
</para>
<note>
<simpara>
Два элемента считаются одинаковыми в том и только в том случае, если
<literal>(string) $elem1 === (string) $elem2</literal>. Другими словами:
если у них одинаковое строковое представление, то будет использован первый элемент.
</simpara>
</note>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>array</parameter></term>
<listitem>
<para>
Входной массив.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>sort_flags</parameter></term>
<listitem>
<para>
Можно использовать необязательный второй параметр <parameter>sort_flags</parameter>
для изменения поведения сортировки с помощью следующих значений:
</para>
<para>
Виды сортировок флагов:
<itemizedlist>
<listitem>
<simpara><constant>SORT_REGULAR</constant> - нормальное сравнение элементов
(типы не меняются)</simpara>
</listitem>
<listitem>
<simpara><constant>SORT_NUMERIC</constant> - элементы сравниваются как числа</simpara>
</listitem>
<listitem>
<simpara><constant>SORT_STRING</constant> - элементы сравниваются как строки</simpara>
</listitem>
<listitem>
<simpara><constant>SORT_LOCALE_STRING</constant> - сравнивает элементы как строки,
с учетом текущей локали.
</simpara>
</listitem>
</itemizedlist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Возвращает отфильтрованный массив.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.2.10</entry>
<entry>
Значение по умолчанию параметра <parameter>sort_flags</parameter> изменено
обратно на <constant>SORT_STRING</constant>.
</entry>
</row>
<row>
<entry>5.2.9</entry>
<entry>
Добавлен необязательный параметр <parameter>sort_flags</parameter>, по
умолчанию равный <constant>SORT_REGULAR</constant>. До версии 5.2.9
это функция сортировала массив с помощью <constant>SORT_STRING</constant>.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Пример использования <function>array_unique</function></title>
<programlisting role="php">
<![CDATA[
<?php
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
Array
(
[a] => green
[0] => red
[1] => blue
)
]]>
</screen>
</example>
</para>
<para>
<example>
<title><function>array_unique</function> и типы:</title>
<programlisting role="php">
<![CDATA[
<?php
$input = array(4, "4", "3", 4, 3, "3");
$result = array_unique($input);
var_dump($result);
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
array(2) {
[0] => int(4)
[2] => string(1) "3"
}
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>array_count_values</function></member>
</simplelist>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<simpara>
Обратите внимание, что <function>array_unique</function> не предназначена
для работы с многомерными массивами.
</simpara>
</note>
</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
-->