Bug #76505 [Ver->Csd]: array_merge_recursive() is duplicating sub-array keys

From: Date: Thu, 21 Jun 2018 09:27:31 +0000
Subject: Bug #76505 [Ver->Csd]: array_merge_recursive() is duplicating sub-array keys
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215824@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 Updated by: laruence@php.net Reported by: german dot drulyk at gmail dot com Summary: array_merge_recursive() is duplicating sub-array keys -Status: Verified +Status: Closed Type: Bug Package: Arrays related Operating System: https://3v4l.org/ PHP Version: 7.2.6 Block user comment: N Private report: N New Comment: Automatic comment on behalf of laruence@gmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=6531719da575e8ceb14fa8e9fefcac2ab365dd00 Log: Fixed bug #76505 (array_merge_recursive() is duplicating sub-array keys) Previous Comments: ------------------------------------------------------------------------ [2018-06-20 15:36:25] german dot drulyk at gmail dot com 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. ------------------------------------------------------------------------ [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? ------------------------------------------------------------------------ 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

« previous php.bugs (#215824) next »