Tribe__Utils__Array::merge_recursive_query_vars( array $arrays )
Merges two or more arrays in the nested format used by WP_Query arguments preserving and merging them correctly.
Contents
The method will recursively replace named keys and merge numeric keys. The method takes its name from its intended primary use, but it’s not limited to query arguments only.
Parameters
- $arrays
-
(<span class="arrayarray<string|">int,mixed>) (Required) A set of arrays to merge.
Return
(array<string|int,mixed>) The recursively merged array.
Source
File: src/Tribe/Utils/Array.php
public static function merge_recursive_query_vars( array ...$arrays ) {
if ( ! count( $arrays ) ) {
return [];
}
// Temporarily transform numeric keys to string keys generated with time-related randomness.
$stringified = array_map( [ static::class, 'stringify_keys' ], $arrays );
// Replace recursive will recursively replace any entry that has the same string key, stringified keys will never match due to randomness.
$merged = array_replace_recursive( ...$stringified );
// Finally destringify the keys to return something that will resemble, in shape, the original arrays.
return static::destringify_keys( $merged );
}
Changelog
| Version | Description |
|---|---|
| 4.12.14 | Introduced. |