#42323 [Opn->Csd]: Details in array_merge page are wrong
| From: | vrana@php.net | Date: | Fri, 17 Aug 2007 02:04:31 +0000 |
| Subject: | #42323 [Opn->Csd]: Details in array_merge page are wrong | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969377493@lists.php.net to get a copy of this message | ||
ID: 42323
Updated by: vrana@php.net
Reported By: kev at projectcolo dot org dot uk
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: N/A
PHP Version: Irrelevant
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
"If you want to completely preserve the arrays and just want to append
them to each other (not overwriting the previous keys), use the +
operator"
Previous Comments:
------------------------------------------------------------------------
[2007-08-16 22:36:17] kev at projectcolo dot org dot uk
Description:
------------
The notes in Example 257 above are incorrect. It states:
If you want to completely preserve the arrays and just want to append
them to each other, use the + operator
Check the array type page at
http://www.php.net/manual/en/language.types.array.php
which states
differently. Duplicate keys are ignored with the + operator.
Reproduce code:
---------------
<?php
$x = array('moon','sky');
$y = array('rain','shine');
var_dump($x + $y);
var_dump(array_merge($x, $y));
?>
Expected result:
----------------
array(2) {
[0]=>
string(4) "moon"
[1]=>
string(3) "sky"
... more values
}
array(4) {
[0]=>
string(4) "moon"
[1]=>
string(3) "sky"
[2]=>
string(4) "rain"
[3]=>
string(5) "shine"
}
Actual result:
--------------
array(2) {
[0]=>
string(4) "moon"
[1]=>
string(3) "sky"
}
array(4) {
[0]=>
string(4) "moon"
[1]=>
string(3) "sky"
[2]=>
string(4) "rain"
[3]=>
string(5) "shine"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42323&edit=1