Bug #77276 [Opn->Csd]: Duplicate keys array_merge_recursive
| From: | mindaugas at osos dot lt | Date: | Mon, 10 Dec 2018 12:31:33 +0000 |
| Subject: | Bug #77276 [Opn->Csd]: Duplicate keys array_merge_recursive | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218362@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77276&edit=1
ID: 77276
User updated by: mindaugas at osos dot lt
Reported by: mindaugas at osos dot lt
Summary: Duplicate keys array_merge_recursive
-Status: Open
+Status: Closed
Type: Bug
Package: Arrays related
Operating System: Linux
PHP Version: 7.0.33
Block user comment: N
Private report: N
New Comment:
Fixed as of Version 7.2.8
#Fixed bug #76505 (array_merge_recursive() is duplicating sub-array keys).
Previous Comments:
------------------------------------------------------------------------
[2018-12-10 12:26:05] mindaugas at osos dot lt
Description:
------------
---
From manual page: https://php.net/function.array-merge-recursive
---
When first array first element has higher index number than second element, then
array_merge_recursive makes duplicate keys. In php 5 was ok, this was tested on 7.0.32 and 7.1.* -
same result.
Test script:
---------------
$aray1 = [
'service' => [
5 => ['jehfkjfhwk'],
2 => ['ejfoiwefoweif']
],
];
$aray2 = [
'service' => [
['qfwwqfqwf'],
['wqfwfqwfqwf1'],
['wqfwfqwfqwf2'],
['wqfwfqwfqwf3'],
['wqfwfqwfqwf4'],
['wqfwfqwfqwf5'],
['wqfwfqwfqwf6'],
],
];
echo '<pre>';
print_r(array_merge_recursive($aaray1, $aaray2));
Expected result:
----------------
Array
(
[service] => Array
(
[5] => Array
(
[0] => jehfkjfhwk
)
[2] => Array
(
[0] => ejfoiwefoweif
)
[6] => Array
(
[0] => qfwwqfqwf
)
[7] => Array
(
[0] => wqfwfqwfqwf1
)
[8] => Array
(
[0] => wqfwfqwfqwf2
)
[9] => Array
(
[0] => wqfwfqwfqwf3
)
[10] => Array
(
[0] => wqfwfqwfqwf4
)
[11] => Array
(
[0] => wqfwfqwfqwf5
)
[12] => Array
(
[0] => wqfwfqwfqwf6
)
)
)
Actual result:
--------------
Array
(
[service] => Array
(
[5] => Array
(
[0] => jehfkjfhwk
)
[2] => Array
(
[0] => ejfoiwefoweif
)
[2] => Array
(
[0] => qfwwqfqwf
)
[3] => Array
(
[0] => wqfwfqwfqwf1
)
[4] => Array
(
[0] => wqfwfqwfqwf2
)
[5] => Array
(
[0] => wqfwfqwfqwf3
)
[6] => Array
(
[0] => wqfwfqwfqwf4
)
[7] => Array
(
[0] => wqfwfqwfqwf5
)
[8] => Array
(
[0] => wqfwfqwfqwf6
)
)
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77276&edit=1