Files
php-doc-ru/reference/array/functions/array-unique.xml
Shein Alexey 8b270b314a Updated translation.
git-svn-id: https://svn.php.net/repository/phpdoc/ru/trunk@307909 c90b9560-bf6c-de11-be94-00142212c4b1
2011-02-01 11:50:17 +00:00

216 lines
6.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: a249d944355b14ea6d7426f91bda3b731c068880 Maintainer: shein Status: ready -->
<!-- Reviewed: no -->
<!-- $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>
Обратите внимание, что ключи сохранятся.
<function>array_unique</function> сначала сортирует
значения как строки, сохраняет первый встреченный ключ
для каждого значения и игнорирует все последующие ключи. Это не означает,
что первый ключ каждого значения неотсортированного
<parameter>array</parameter> будет сохранён.
</para>
<note>
<simpara>
Два элемента считаются одинаковыми в том и только в том случае, если
<literal>(string) $elem1 === (string) $elem2</literal>. Другими словами:
если у них одинаковое строковое представление.
</simpara>
<simpara>
Будет использован первый элемент.
</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> - элементы сравниваются
как строки, в зависимости от установленной локали.
<!--
FIXME: PHP_6
Before PHP 6, it uses the system locale, which can be changed using
<function>setlocale</function>. Since PHP 6, you must use the
<function>i18n_loc_set_default</function> function.
-->
</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> изменено
обратно на SORT_STRING.
</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="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
-->