Arr::mergeRecursive()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 7
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 13
rs 9.6111
1
<?php
2
3
/*
4
 * This file is part of the PHINT package.
5
 *
6
 * (c) Jitendra Adhikari <[email protected]>
7
 *     <https://github.com/adhocore>
8
 *
9
 * Licensed under MIT license.
10
 */
11
12
namespace Ahc\Phint\Util;
13
14
class Arr
15
{
16
    /**
17
     * @see http://php.net/array_merge_recursive#92195
18
     *
19
     * @param array $array1
20
     * @param array $array2
21
     *
22
     * @return array
23
     */
24
    public static function mergeRecursive(array $array1, array $array2)
25
    {
26
        $merged = $array1;
27
28
        foreach ($array2 as $key => &$value) {
29
            if (\is_array($value) && isset($merged[$key]) && \is_array($merged[$key])) {
30
                $merged[$key] = self::mergeRecursive($merged[$key], $value);
31
            } else {
32
                $merged[$key] = $value;
33
            }
34
        }
35
36
        return $merged;
37
    }
38
}
39