1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* The MIT License |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 Daniel Popiniuc |
7
|
|
|
* |
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
10
|
|
|
* in the Software without restriction, including without limitation the rights |
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
13
|
|
|
* furnished to do so, subject to the following conditions: |
14
|
|
|
* |
15
|
|
|
* The above copyright notice and this permission notice shall be included in |
16
|
|
|
* all copies or substantial portions of the Software. |
17
|
|
|
* |
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
24
|
|
|
* THE SOFTWARE. |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace danielgp\info_compare; |
28
|
|
|
|
29
|
|
|
trait CompareResults |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
private function decideToReturn($inValue) |
33
|
|
|
{ |
34
|
|
|
if (isset($inValue)) { |
35
|
|
|
$sReturn = $inValue; |
36
|
|
|
} else { |
37
|
|
|
$sReturn = ''; |
38
|
|
|
} |
39
|
|
|
return $sReturn; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function mergeArraysIntoFirstSecond($firstArray, $secondArray, $pSequence = ['first', 'second']) |
43
|
|
|
{ |
44
|
|
|
$row = []; |
45
|
|
|
foreach ($firstArray as $key => $value) { |
46
|
|
|
if (is_array($value)) { |
47
|
|
|
foreach ($value as $key2 => $value2) { |
48
|
|
|
if (is_array($value2)) { |
49
|
|
|
foreach ($value2 as $key3 => $value3) { |
50
|
|
|
if (is_array($value3)) { |
51
|
|
|
foreach ($value3 as $key4 => $value4) { |
52
|
|
|
$keyCrt = $key . '_' . $key2 . '__' . $key3 . '__' . $key4; |
53
|
|
|
$row[$keyCrt][$pSequence[0]] = $value4; |
54
|
|
|
$toEval = $secondArray[$key][$key2][$key3][$key4]; |
55
|
|
|
$row[$keyCrt][$pSequence[1]] = $this->decideToReturn($toEval); |
56
|
|
|
} |
57
|
|
|
} else { |
58
|
|
|
$keyCrt = $key . '_' . $key2 . '__' . $key3; |
59
|
|
|
$row[$keyCrt][$pSequence[0]] = $value3; |
60
|
|
|
$row[$keyCrt][$pSequence[1]] = $this->decideToReturn($secondArray[$key][$key2][$key3]); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} else { |
64
|
|
|
$keyCrt = $key . '_' . $key2; |
65
|
|
|
$row[$keyCrt][$pSequence[0]] = $value2; |
66
|
|
|
$row[$keyCrt][$pSequence[1]] = $this->decideToReturn($secondArray[$key][$key2]); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} else { |
70
|
|
|
$row[$key][$pSequence[0]] = $value; |
71
|
|
|
$row[$key][$pSequence[1]] = $this->decideToReturn($secondArray[$key]); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
return $row; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|