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@94824 c90b9560-bf6c-de11-be94-00142212c4b1
126 lines
3.1 KiB
XML
Executable File
126 lines
3.1 KiB
XML
Executable File
<?xml version="1.0" encoding="gb2312"?>
|
|
<!-- $Revision: 1.1 $ -->
|
|
<!-- $Author: dallas $ -->
|
|
<!-- EN-Revision: 1.6 Maintainer: dallas Status: ready -->
|
|
<refentry id="function.array-merge">
|
|
<refnamediv>
|
|
<refname>array_merge</refname>
|
|
<refpurpose>合并两个或多个数组</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>说明</title>
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>array_merge</methodname>
|
|
<methodparam><type>array</type><parameter>array1</parameter></methodparam>
|
|
<methodparam><type>array</type><parameter>array2</parameter></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter>...</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>array_merge</function> 将两个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面。返回作为结果的数组。
|
|
</para>
|
|
<para>
|
|
如果输入的数组中有相同的字符串键名,则该键名后面的值将覆盖前一个值。然而,如果数组包含数字键名,后面的值将<emphasis role="strong">不会</emphasis>覆盖原来的值,而是附加到后面。
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>array_merge</function> 例子</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
$array1 = array ("color" => "red", 2, 4);
|
|
$array2 = array ("a", "b", "color" => "green", "shape" => "trapezoid", 4);
|
|
$result = array_merge ($array1, $array2);
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
<literal>$result</literal> 成为:
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[color] => green
|
|
[0] => 2
|
|
[1] => 4
|
|
[2] => a
|
|
[3] => b
|
|
[shape] => trapezoid
|
|
[4] => 4
|
|
)
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>简单的 <function>array_merge</function> 例子</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
$array1 = array();
|
|
$array2 = array(1 => "data");
|
|
$result = array_merge($array1, $array2);
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
别忘了数字键名将会被重新编号!
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => data
|
|
)
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
<para>
|
|
如果你想完全保留原有数组并只想新的数组附加到后面,用 <literal>+</literal> 运算符:
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
$array1 = array();
|
|
$array2 = array(1 => "data");
|
|
$result = $array1 + $array2;
|
|
]]>
|
|
</programlisting>
|
|
数字键名将被保留从而原来的关联保持不变。
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => data
|
|
)
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
</example>
|
|
</para>
|
|
<note>
|
|
<para>
|
|
共有的键名将根据先来先服务的原则被覆盖掉。
|
|
</para>
|
|
</note>
|
|
<para>
|
|
参见 <function>array_merge_recursive</function>。
|
|
</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
|
|
-->
|