Download the PHP package rikudou/array-merge-recursive without Composer
On this page you can find all versions of the php package rikudou/array-merge-recursive. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rikudou/array-merge-recursive
More information about rikudou/array-merge-recursive
Files in rikudou/array-merge-recursive
Package array-merge-recursive
Short Description Replacement of built-in array_merge_recursive function that doesn't add values to array but replaces them
License WTFPL
Informations about the package array-merge-recursive
array_merge_recursive replacement
Installation
composer require rikudou/array-merge-recursive
Description
The php function array_merge_recursive
behaves a little confusingly and not at all like
array_merge
.
Example of confusing behavior:
As you can see, the built in function doesn't replace the same keys but instead merges them together.
Compared to regular array_merge
:
The array_merge
replaces the values with whatever comes
latest but doesn't work for deep array structures.
This library replaces the array_merge_recursive
behavior to work
like regular array_merge
while maintaining the ability
to merge deep arrays recursively.
Example:
Deeper level array example
These two arrays are used in the following example:
Result of built-in array_merge_recursive
Here you can see that key2
gets changed to array with both values
added.
Result of built-in array_merge
Since array_merge
doesn't work recursively it completely replaces
the test
key with value from 2nd array.
Result of array_merge_recursive
from this library
This library correctly replaces the key2
with later value
while keeping the whole tree.