Bug #76511 [NEW]: array_merge_recursive() treats root indexed array keys differently than sub-arr
| From: | german dot drulyk at gmail dot com | Date: | Thu, 21 Jun 2018 12:32:21 +0000 |
| Subject: | Bug #76511 [NEW]: array_merge_recursive() treats root indexed array keys differently than sub-arr | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-215832@lists.php.net to get a copy of this message | ||
From: german dot drulyk at gmail dot com
Operating system: https://3v4l.org/
PHP version: Irrelevant
Package: Arrays related
Bug Type: Bug
Bug description:array_merge_recursive() treats root indexed array keys differently than sub-arr
Description:
------------
I am not sure which behavior is the bug but the root array gets
re-indexed to 0 and 1 and the array at position "k" goes from 4 to 5.
array_merge() exhibits the same behavior with the root array.
Test script:
---------------
$arr1 = array(
4 => 'a',
'k' => array( 4 => 'a' )
);
$arr2 = array(
5 => 'b',
'k' => array( 5 => 'b' )
);
$arr3 = array_merge_recursive( $arr1, $arr2 );
var_dump( $arr3 );
Expected result:
----------------
array(3) {
[0]=> // Should this be 4?
string(1) "a"
["k"]=>
array(2) {
[4]=> // or should this be 0?
string(1) "a"
[5]=> // or should this be 1?
string(1) "b"
}
[1]=> // Should this be 5?
string(1) "b"
}
Actual result:
--------------
array(3) {
[0]=>
string(1) "a"
["k"]=>
array(2) {
[4]=>
string(1) "a"
[5]=>
string(1) "b"
}
[1]=>
string(1) "b"
}
--
Edit bug report at https://bugs.php.net/bug.php?id=76511&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76511&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76511&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76511&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76511&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76511&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76511&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76511&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76511&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76511&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76511&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76511&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76511&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76511&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76511&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76511&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76511&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76511&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76511&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76511&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76511&r=mysqlcfg