array_replace_recursive() Alternative

Background

I was using array_replace_recursive() to merge default option values and user-defined parameter values. However, it is supported in PHP 5.3 or above. Then some of my users reported that my plugin does not work with a fatal error.

So I wrote up an alternative for it. One limitation though is that it only accepts two parameters unlike the PHP’s array_replace_recursive() which supports more than two.

Anyhow this is the code and hope it helps somebody else who gets a similar issue.

Code

Example

Result

One thought on “array_replace_recursive() Alternative

  1. James

    Just be aware the parameters to uniteArraysRecursive() are the opposite way round to PHP’s array_replace_recursive()

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *