|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75483 array_replace_recursive will merge (not replace), when both values are arrays
Submitted: 2017-11-03 15:08 UTC Modified: 2017-11-03 15:16 UTC
From: gladykov at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 7.1.11 OS:
Private report: No CVE-ID: None
 [2017-11-03 15:08 UTC] gladykov at gmail dot com
array_replace_recursive will merge (not replace) values, when both key values in original and replacement matching key are arrays.

When one of values either in original key or replacement key is string, replacement will occur properly.

Test script:

//If value of availableReport key will be string in $original OR $replacement array_replace_recursive will work properly

$original = [
'availableReports' => ['InternalReview' => 'Internal Review'],

$replacements = [
    'availableReports' => ['AppraisalRev' => 'Commercial Appraisal Review']

//Will print both values in current implementation
print_r(array_replace_recursive($original, $replacements));


Expected result:
    [availableReports] => Array
            [AppraisalRev] => Commercial Appraisal Review

Actual result:
    [availableReports] => Array
            [InternalReview] => Internal Review
            [AppraisalRev] => Commercial Appraisal Review


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-11-03 15:16 UTC]
-Status: Open +Status: Not a bug
 [2017-11-03 15:16 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Well, yeah. Because it's recursive. Wouldn't be much point to a recursive function that doesn't act recursively.

Perhaps you want to use the regular array_replace?
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Jul 03 05:03:40 2022 UTC