1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-28 00:52:06 +01:00
Files
archived-doc-zh/reference/array/functions/array-unique.xml
Dallas Wang 39186f910d Updated.
git-svn-id: https://svn.php.net/repository/phpdoc/zh/trunk@194401 c90b9560-bf6c-de11-be94-00142212c4b1
2005-08-25 19:04:04 +00:00

105 lines
2.5 KiB
XML
Executable File

<?xml version="1.0" encoding="gb2312"?>
<!-- $Revision: 1.5 $ -->
<!-- $Author: dallas $ -->
<!-- EN-Revision: 1.14 Maintainer: dallas Status: ready -->
<refentry id="function.array-unique">
<refnamediv>
<refname>array_unique</refname>
<refpurpose>移除数组中重复的值</refpurpose>
</refnamediv>
<refsect1>
<title>说明</title>
<methodsynopsis>
<type>array</type><methodname>array_unique</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<para>
<function>array_unique</function> 接受
<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>
<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>
</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
-->