Bug #76505 [Com]: array_merge_recursive() is duplicating sub-array keys
| From: | german dot drulyk at gmail dot com | Date: | Wed, 20 Jun 2018 15:36:26 +0000 |
| Subject: | Bug #76505 [Com]: array_merge_recursive() is duplicating sub-array keys | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215815@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76505&edit=1
ID: 76505
Comment by: german dot drulyk at gmail dot com
Reported by: german dot drulyk at gmail dot com
Summary: array_merge_recursive() is duplicating sub-array
keys
Status: Verified
Type: Bug
Package: Arrays related
Operating System: https://3v4l.org/
PHP Version: 7.2.6
Block user comment: N
Private report: N
New Comment:
I see some discussion centered around the expected result and just wanted to chime in.
Numeric keys in the root array are treated differently than sub-arrays.
Previous Comments:
------------------------------------------------------------------------
[2018-06-20 14:30:18] requinix@php.net
> | If, however, the arrays have the same numeric key, the later
> | value will not overwrite the original value, but will be appended.
Right, but here they aren't "the same numeric key". The 64 only exists in the second
array.
The truth is that numeric keys' values are always appended, regardless of whether they existed
in the first array.
------------------------------------------------------------------------
[2018-06-20 14:21:57] cmb@php.net
> But shouldn't the expected result have 64=>300 and not 99=>300?
The docs say[1]:
| If, however, the arrays have the same numeric key, the later
| value will not overwrite the original value, but will be appended.
[1] <http://php.net/manual/en/function.array-merge-recursive.php>
------------------------------------------------------------------------
[2018-06-20 14:21:10] requinix@php.net
> But shouldn't the expected result have 64=>300 and not 99=>300?
Actually no. The docs aren't exactly clear on this but I believe it's intended behavior
that values in the second array having numeric keys are appended rather than created using the same
key.
------------------------------------------------------------------------
[2018-06-20 14:16:52] requinix@php.net
https://3v4l.org/6ivO9 Bizarre.
But shouldn't the expected result have 64=>300 and not 99=>300?
------------------------------------------------------------------------
[2018-06-20 13:30:48] german dot drulyk at gmail dot com
PHP 4.x and 5.x produce the expected result but PHP 7.x does not.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=76505
--
Edit this bug report at https://bugs.php.net/bug.php?id=76505&edit=1