array_merge_recursive_distinct()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 9
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 16
ccs 0
cts 8
cp 0
crap 30
rs 9.6111
1
<?php
2
3
if (! function_exists('array_merge_recursive_distinct')) {
4
    /**
5
     * Recursively merge two config arrays - retain distinct values and overwrite existing values.
6
     * @see http://docs.php.net/manual/da/function.array-merge-recursive.php#92195
7
     * @param array $array1
8
     * @param array $array2
9
     *
10
     * @return array
11
     */
12
    function array_merge_recursive_distinct(array &$array1, array &$array2)
13
    {
14
        $merged = $array1;
15
16
        foreach ($array2 as $key => &$value) {
17
            if (is_array($value) &&
18
                isset($merged[$key]) &&
19
                is_array($merged[$key])
20
            ) {
21
                $merged[$key] = array_merge_recursive_distinct($merged[$key], $value);
22
            } else {
23
                $merged[$key] = $value;
24
            }
25
        }
26
27
        return $merged;
28
    }
29
}
30