svn: /phpdoc/en/trunk/reference/array/functions/ array-merge.xml
| From: | Torben Wilson | Date: | Fri, 28 Aug 2009 08:34:04 +0000 |
| Subject: | svn: /phpdoc/en/trunk/reference/array/functions/ array-merge.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-4789@lists.php.net to get a copy of this message | ||
torben Fri, 28 Aug 2009 08:34:04 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=287831
Log:
Fixed an old incorrect description of array union.
Addresses bug #46765.
Bug: http://bugs.php.net/46765 (Open) array_merge
documentation incorrectly states that "arrays will be preserved"
Changed paths:
U phpdoc/en/trunk/reference/array/functions/array-merge.xml
Modified: phpdoc/en/trunk/reference/array/functions/array-merge.xml
===================================================================
--- phpdoc/en/trunk/reference/array/functions/array-merge.xml 2009-08-28 07:29:59 UTC (rev 287830)
+++ phpdoc/en/trunk/reference/array/functions/array-merge.xml 2009-08-28 08:34:04 UTC (rev 287831)
@@ -169,28 +169,41 @@
]]>
</screen>
<para>
- If you want to completely preserve the arrays and just want to append
- them to each other (not overwriting the previous keys), use the
- <literal>+</literal> operator:
+ If you want to append array elements from the second array to the
+ first array while not overwriting the elements from the first
+ array and not re-indexing, use the
+ <literal>+</literal> array union operator:
</para>
<programlisting role="php">
<![CDATA[
<?php
-$array1 = array();
-$array2 = array(1 => "data");
+$array1 = array(0 => 'zero_a', 2 => 'two_a', 3 =>
'three_a');
+$array2 = array(1 => 'one_b', 3 => 'three_b', 4 =>
'four_b');
$result = $array1 + $array2;
+var_dump($result);
?>
]]>
</programlisting>
<para>
- The numeric key will be preserved and thus the association remains.
+ The keys from the first array will be preserved. If an array key
+ exists in both arrays, then the element from the first array will
+ be used and the matching key's element from the second array will
+ be ignored.
</para>
<screen role="php">
<![CDATA[
-Array
-(
- [1] => data
-)
+array(5) {
+ [0]=>
+ string(6) "zero_a"
+ [2]=>
+ string(5) "two_a"
+ [3]=>
+ string(7) "three_a"
+ [1]=>
+ string(5) "one_b"
+ [4]=>
+ string(6) "four_b"
+}
]]>
</screen>
</example>