Bug #77276 [NEW]: Duplicate keys array_merge_recursive
| From: | mindaugas at osos dot lt | Date: | Mon, 10 Dec 2018 12:26:05 +0000 |
| Subject: | Bug #77276 [NEW]: Duplicate keys array_merge_recursive | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-218361@lists.php.net to get a copy of this message | ||
From: mindaugas at osos dot lt
Operating system: Linux
PHP version: 7.0.33
Package: Arrays related
Bug Type: Bug
Bug description:Duplicate keys array_merge_recursive
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 bug report at https://bugs.php.net/bug.php?id=77276&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77276&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77276&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77276&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77276&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77276&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77276&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77276&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77276&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77276&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77276&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77276&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77276&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77276&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77276&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77276&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77276&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77276&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77276&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77276&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77276&r=mysqlcfg