ArrayDiff::arrayDiffRecursive()   B
last analyzed

Complexity

Conditions 7
Paths 6

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 13
c 1
b 0
f 0
nc 6
nop 2
dl 0
loc 22
rs 8.8333
1
<?php
2
3
namespace Locastic\Loggastic\Util;
4
5
final class ArrayDiff
6
{
7
    public static function arrayDiffRecursive($array1, $array2): array
8
    {
9
        $return = [];
10
11
        foreach ($array1 as $key => $value) {
12
            if (is_array($array2) && array_key_exists($key, $array2)) {
13
                if (is_array($value)) {
14
                    $recursiveDiff = self::arrayDiffRecursive($value, $array2[$key]);
15
                    if (count($recursiveDiff)) {
16
                        $return[$key] = $recursiveDiff;
17
                    }
18
                } else {
19
                    if ($value != $array2[$key]) {
20
                        $return[$key] = $value;
21
                    }
22
                }
23
            } else {
24
                $return[$key] = $value;
25
            }
26
        }
27
28
        return $return;
29
    }
30
}
31