Utils/ArrayUtils.php
/**
     * Merges any number of arrays / parameters recursively, replacing
     * entries with string keys with values from latter arrays.
     * If the entry or the next value to be assigned is an array, then it
     * automagically treats both arguments as an array.
     * Numeric entries are appended, not replaced, but only if they are
     * unique
     *
     * @example result = array_merge_recursive_distinct(a1, a2, ... aN)
     * Credit: mark.roduner@gmail.com on http://php.net/manual/en/function.array-merge-recursive.php
     * */
Merges any number of arrays / parameters recursively, replacing
entries with string keys with values from latter arrays.
If the entry or the next value to be assigned is an array, then it
automagically treats both arguments as an array.
Numeric entries are appended, not replaced, but only if they are
unique

@example result = array_merge_recursive_distinct(a1, a2, ...
Merges any number of arrays / parameters recursively replacing entries with string keys with values from latter arrays . If the entry or the next value to be assigned is an array then it automagically treats both arguments as an array . Numeric entries are appended not replaced but only if they are unique @example result = array_merge_recursive_distinct ( a1 a2 ...
public static function arrayMergeRecursiveDistinct()
    {
        $arrays = func_get_args();
        $base   = array_shift($arrays);
        if (!is_array($base)) {
            $base = empty($base) ? array() : array($base);
        }
        foreach ($arrays as $append) {
            if (!is_array($append)) {
                $append = array($append);
            }
            foreach ($append as $key => $value) {
                if (!array_key_exists($key, $base) and !is_numeric($key)) {
                    $base[$key] = $append[$key];
                    continue;
                }
                if (is_array($value) or is_array($base[$key])) {
                    $base[$key] = self::arrayMergeRecursiveDistinct($base[$key], $append[$key]);
                } else if (is_numeric($key)) {
                    if (!in_array($value, $base)) {
                        $base[] = $value;
                    }
                } else {
                    $base[$key] = $value;
                }
            }
        }
        return $base;
    }
public static function arrayMergeRecursiveDistinct ( ) { $ arrays = func_get_args ( ) ; $ base = array_shift ( $ arrays ) ; if ( ! is_array ( $ base ) ) { $ base = empty ( $ base ) ? array ( ) : array ( $ base ) ; } foreach ( $ arrays as $ append ) { if ( ! is_array ( $ append ) ) { $ append = array ( $ append ) ; } foreach ( $ append as $ key => $ value ) { if ( ! array_key_exists ( $ key , $ base ) and ! is_numeric ( $ key ) ) { $ base [ $ key ] = $ append [ $ key ] ; continue ; } if ( is_array ( $ value ) or is_array ( $ base [ $ key ] ) ) { $ base [ $ key ] = self :: arrayMergeRecursiveDistinct ( $ base [ $ key ] , $ append [ $ key ] ) ; } else if ( is_numeric ( $ key ) ) { if ( ! in_array ( $ value , $ base ) ) { $ base [ ] = $ value ; } } else { $ base [ $ key ] = $ value ; } } } return $ base ; }
Merges any number of arrays / parameters recursively, replacing
 entries with string keys with values from latter arrays.
Merges any number of arrays / parameters recursively replacing entries with string keys with values from latter arrays .