Merge ViewHelper <f:merge>
The MergeViewHelper merges two arrays into one, optionally recursively.
It works similar to the PHP functions array_merge() and array_merge_recursive(), depending on the value of the "recursive" argument.
Example
Simple merge
<f:merge array="{0: 'a', 1: 'b'}" with="{1: 'x', 2: 'c'}" />
Copied!
Result:
{0: 'a', 1: 'x', 2: 'c'}
Copied!
Recursive merge
<f:merge array="{foo: {bar: 'baz'}}" with="{foo: {qux: 'value'}}" recursive="true" />
Copied!
Result:
{foo: {bar: 'baz', qux: 'value'}}
Copied!
Inline notation
{f:variable(name: 'myArray', value: {foo: 1})}
{myArray -> f:merge(with: {bar: 2})}
Copied!
Result:
{foo: 1, bar: 2}
Copied!
Go to the source code of this ViewHelper: MergeViewHelper.php (GitHub).
Arguments
The following arguments are available for the merge ViewHelper:
array
-
- Type
- array
The array to merge into
recursive
-
- Type
- boolean
- Default
- false
Whether to merge arrays recursively
with
-
- Type
- array
Array to be merged