Completed
Push — master ( dfd004...b46837 )
by Jitendra
11s
created

Arr::mergeRecursive()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 7
nc 3
nop 2
dl 0
loc 13
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Ahc\Phint\Util;
4
5
class Arr
6
{
7
    /**
8
     * @see http://php.net/array_merge_recursive#92195
9
     *
10
     * @param array $array1
11
     * @param array $array2
12
     *
13
     * @return array
14
     */
15
    public static function mergeRecursive(array $array1, array $array2)
16
    {
17
        $merged = $array1;
18
19
        foreach ($array2 as $key => &$value) {
20
            if (\is_array($value) && isset($merged[$key]) && \is_array($merged[$key])) {
21
                $merged[$key] = self::mergeRecursive($merged[$key], $value);
22
            } else {
23
                $merged[$key] = $value;
24
            }
25
        }
26
27
        return $merged;
28
    }
29
}
30