Req #23816 [Fbk->NoF]: modified array_merge_recursive: array_merge_clobber
| From: | php-bugs at lists dot php dot net | Date: | Tue, 30 Dec 2014 10:41:21 +0000 |
| Subject: | Req #23816 [Fbk->NoF]: modified array_merge_recursive: array_merge_clobber | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-189365@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: php-bugs@lists.php.net
Reported by: pacha_shevaev at mail dot ru
Summary: modified array_merge_recursive: array_merge_clobber
-Status: Feedback
+Status: No Feedback
Type: Feature/Change Request
Package: *General Issues
Operating System: Any
PHP Version: *
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2014-04-16 18:27:18] levim@php.net
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);
------------------------------------------------------------------------
[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