mirror of
https://github.com/php/doc-zh.git
synced 2026-03-26 08:02:16 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/zh/trunk@95449 c90b9560-bf6c-de11-be94-00142212c4b1
114 lines
2.7 KiB
XML
Executable File
114 lines
2.7 KiB
XML
Executable File
<?xml version="1.0" encoding="gb2312"?>
|
||
<!-- $Revision: 1.1 $ -->
|
||
<!-- $Author: dallas $ -->
|
||
<!-- EN-Revision: 1.4 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> 时两个单元被认为相同。就是说,当字符串的表达一样时。
|
||
<!-- TODO: example of it... -->
|
||
</simpara>
|
||
<simpara>
|
||
第一个单元将被保留。
|
||
</simpara>
|
||
</note>
|
||
<warning>
|
||
<simpara>
|
||
本函数在 PHP 4.0.4 中是坏的!
|
||
<!-- TODO: when exactly was this broken?... -->
|
||
</simpara>
|
||
</warning>
|
||
<para>
|
||
<example>
|
||
<title><function>array_unique</function> 例子</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
$input = array ("a" => "green", "red", "b" => "green", "blue", "red");
|
||
$result = array_unique ($input);
|
||
print_r($result);
|
||
]]>
|
||
</programlisting>
|
||
<para>
|
||
上例将输出:
|
||
<screen role="php">
|
||
<![CDATA[
|
||
Array
|
||
(
|
||
[b] => green
|
||
[1] => blue
|
||
[2] => red
|
||
)
|
||
]]>
|
||
</screen>
|
||
</para>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
<example>
|
||
<title><function>array_unique</function> 和类型</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
$input = array (4,"4","3",4,3,"3");
|
||
$result = array_unique ($input);
|
||
var_dump($result);
|
||
]]>
|
||
</programlisting>
|
||
<para>
|
||
以上程序输出结果为(PHP 4.0.6):
|
||
<screen role="php">
|
||
<![CDATA[
|
||
array(2) {
|
||
[0]=>
|
||
int(4)
|
||
[2]=>
|
||
string(1) "3"
|
||
}
|
||
]]>
|
||
</screen>
|
||
</para>
|
||
</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
|
||
-->
|