Req #23816 [Opn->Fbk]: modified array_merge_recursive: array_merge_clobber

From: Date: Wed, 16 Apr 2014 18:27:19 +0000
Subject: Req #23816 [Opn->Fbk]: modified array_merge_recursive: array_merge_clobber
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185291@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=23816&edit=1 ID: 23816 Updated by: levim@php.net Reported by: pacha_shevaev at mail dot ru Summary: modified array_merge_recursive: array_merge_clobber -Status: Open +Status: Feedback Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues -Operating System: win2000 +Operating System: Any -PHP Version: 4.3.1 +PHP Version: * Block user comment: N Private report: N New Comment: If I understand you correctly, the + operator can be used: $array1 = array(0 => 'zero_a', 2 => 'two_a', 3 => 'three_a'); $array2 = array(1 => 'one_b', 3 => 'three_b', 4 => 'four_b'); $result = $array1 + $array2; var_dump($result); Previous Comments: ------------------------------------------------------------------------ [2003-05-26 13:18:21] pacha_shevaev at mail dot ru It's not probably a bug report but a suggestion. Guys please could you make built-in function array_merge_clobber that WOULDN'T append duplicate key/values like array_merge_recursive does? There's an example of such function in the php manual, in the array_merge_recursive section: function array_merge_clobber($a1,$a2) { if(!is_array($a1) || !is_array($a2)) return false; $newarray = $a1; foreach ($a2 as $key => $val) { if (is_array($val) && is_array($newarray[$key])) { $newarray[$key] = array_merge_clobber($newarray[$key],$val); } else { $newarray[$key] = $val; } } return $newarray; } Our application heavily depends on this function and it takes about 40% of overall script execution(very large and nested arrays)! I think many developers would agree to have this function interbally implemented. Maybe it's not the right place...but i have no idea where else i could ask about it... ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=23816&edit=1

« previous php.bugs (#185291) next »