[prev in list] [next in list] [prev in thread] [next in thread]
List: php-doc-cvs
Subject: [DOC-CVS] svn: /phpdoc/en/trunk/reference/array/functions/ array-merge.xml
From: Torben_Wilson <torben () php ! net>
Date: 2009-08-28 8:34:04
Message-ID: svn-torben-1251448444-287831-1111521074 () svn ! php ! net
[Download RAW message or body]
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>
--
PHP Documentation Commits Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic