Bug #77276 [Csd->Dup]: Duplicate keys array_merge_recursive

From: Date: Mon, 10 Dec 2018 15:23:55 +0000
Subject: Bug #77276 [Csd->Dup]: Duplicate keys array_merge_recursive
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218368@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 Updated by: cmb@php.net Reported by: mindaugas at osos dot lt Summary: Duplicate keys array_merge_recursive -Status: Closed +Status: Duplicate Type: Bug Package: Arrays related Operating System: Linux PHP Version: 7.0.33 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2018-12-10 12:31:33] mindaugas at osos dot lt Fixed as of Version 7.2.8 #Fixed bug #76505 (array_merge_recursive() is duplicating sub-array keys). ------------------------------------------------------------------------ [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

« previous php.bugs (#218368) next »