@@ 45-82 (lines=38) @@ | ||
42 | return $diff_array; |
|
43 | } |
|
44 | ||
45 | public static function joinDicts($leftDicts, $rightDicts, $leftDictsColumnIndex = 0, $rightDictsColumnIndex = 0) |
|
46 | { |
|
47 | if (count($leftDicts) == 0) { |
|
48 | return $rightDicts; |
|
49 | } |
|
50 | if (count($rightDicts) == 0) { |
|
51 | return $leftDicts; |
|
52 | } |
|
53 | ||
54 | $leftKeys = array_keys($leftDicts[0]); |
|
55 | $leftKey = $leftKeys[$leftDictsColumnIndex]; |
|
56 | $rightKeys = array_keys($rightDicts[0]); |
|
57 | $rightKey = $rightKeys[$rightDictsColumnIndex]; |
|
58 | ||
59 | foreach ($leftDicts as $lk => $lv) { |
|
60 | foreach ($rightDicts as $rk => $rv) { |
|
61 | if ($lv[$leftKey] != $rv[$rightKey]) { |
|
62 | continue; |
|
63 | } |
|
64 | $leftDicts[$lk] = array_merge($lv, $rv); |
|
65 | } |
|
66 | } |
|
67 | ||
68 | $keys = []; |
|
69 | foreach ($leftDicts as $dict) { |
|
70 | $keys = array_unique(array_merge($keys, array_keys($dict))); |
|
71 | } |
|
72 | ||
73 | foreach ($leftDicts as $dictKey => $dict) { |
|
74 | foreach ($keys as $key) { |
|
75 | if (!isset($leftDicts[$dictKey][$key])) { |
|
76 | $leftDicts[$dictKey][$key] = null; |
|
77 | } |
|
78 | } |
|
79 | } |
|
80 | ||
81 | return $leftDicts; |
|
82 | } |
|
83 | ||
84 | /** |
|
85 | * @param $from_list |
@@ 94-135 (lines=42) @@ | ||
91 | * @param int $right_dicts_column_index_to_join |
|
92 | * @return mixed |
|
93 | */ |
|
94 | public static function join( |
|
95 | $left_dicts, |
|
96 | $right_dicts, |
|
97 | $left_dicts_column_index_to_join = 0, |
|
98 | $right_dicts_column_index_to_join = 0 |
|
99 | ) { |
|
100 | if (count($left_dicts) == 0) { |
|
101 | return $right_dicts; |
|
102 | } |
|
103 | if (count($right_dicts) == 0) { |
|
104 | return $left_dicts; |
|
105 | } |
|
106 | ||
107 | $left_keys = array_keys($left_dicts[0]); |
|
108 | $left_key_to_join = $left_keys[$left_dicts_column_index_to_join]; |
|
109 | $right_keys = array_keys($right_dicts[0]); |
|
110 | $right_key_to_join = $right_keys[$right_dicts_column_index_to_join]; |
|
111 | ||
112 | foreach ($left_dicts as $lk => $lv) { |
|
113 | foreach ($right_dicts as $rk => $rv) { |
|
114 | if ($lv[$left_key_to_join] != $rv[$right_key_to_join]) { |
|
115 | continue; |
|
116 | } |
|
117 | $left_dicts[$lk] = array_merge($lv, $rv); |
|
118 | } |
|
119 | } |
|
120 | ||
121 | $keys = []; |
|
122 | foreach ($left_dicts as $dict) { |
|
123 | $keys = array_unique(array_merge($keys, array_keys($dict))); |
|
124 | } |
|
125 | ||
126 | foreach ($left_dicts as $dictKey => $dict) { |
|
127 | foreach ($keys as $key) { |
|
128 | if (!isset($left_dicts[$dictKey][$key])) { |
|
129 | $left_dicts[$dictKey][$key] = null; |
|
130 | } |
|
131 | } |
|
132 | } |
|
133 | ||
134 | return $left_dicts; |
|
135 | } |
|
136 | ||
137 | public static function convertDictsToHtmlTable($dicts) |
|
138 | { |