class_mcArray.inc.php
5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* @todo
* könnte in
* SEOLinkCache eingesetzt werden
*/
class mcArray {
const ARRAY_MIDDLE = '=';
const ARRAY_START = '|_';
const ARRAY_STOP = '_|';
/**
* transform a array to a string ... in example for SEOLink
*
* @phpunit
*
* @param array $param_Array -- array( key1=>var1, key2=>var2, ...)
* @param string $param_StartSeperator
* @param string $param_MiddleSeperator
* @param string $param_StopSeperator
* @return string -- $param_StartSeperator
* .key1.$param_MiddleSeperator.var1.$param_MiddleSeperator
* .key2.$param_MiddleSeperator.var2.$param_StopSeperator
*/
public static function transformArrayToString(array $param_Array, $param_StartSeperator=SEOLink::ARRAY_START, $param_MiddleSeperator=SEOLink::ARRAY_MIDDLE, $param_StopSeperator=SEOLink::ARRAY_STOP) {
$return = '';
if(is_array($param_Array)) {
$return .= $param_StartSeperator;
$tmp_notfirst = false;
foreach($param_Array as $Aindex => $Avalue) {
if(is_array($Avalue)) {
D::cf('transformArrayToSEOLink rekursiv fürs Array noch nicht entwickelt');
} else {
if($tmp_notfirst) {
$return .= ''.$param_MiddleSeperator;
} else {
$tmp_notfirst = true ;
}
$return .= ''.$Aindex.$param_MiddleSeperator.$Avalue;
}
}
$return .= $param_StopSeperator;
}
return $return;
}
/**
* check if key path is in array and value is not emtpy array
*
* @phpunit
*
* @param array $param_Array
* @param string $param_key -- $param_Array[$param_key]
* @param string $param_key2 -- $param_Array[$param_key][$param_key2]
* @param string $param_key3 -- $param_Array[$param_key][$param_key2][$param_key3]
* @param string $param_key4 -- $param_Array[$param_key][$param_key2][$param_key3][$param_key4]
* @param string $param_key5 -- $param_Array[$param_key][$param_key2][$param_key3][$param_key4][$param_key5]
* @param string $param_key6 -- $param_Array[$param_key][$param_key2][$param_key3][$param_key4][$param_key5][$param_key6]
* @return bool
*/
public static function checkKeyHasFullArray($param_Array, $param_key, $param_key2=null, $param_key3=null, $param_key4=null, $param_key5=null, $param_key6=null) {
if(is_array($param_Array)) {
if(array_key_exists($param_key, $param_Array)
&& is_array($param_Array[$param_key])
&& !empty($param_Array[$param_key])
) {
if(is_null($param_key2)) {
return true;
} else {
return mcArray::checkKeyHasFullArray($param_Array[$param_key], $param_key2, $param_key3, $param_key4, $param_key5);
}
} else {
return false;
}
} else {
return false;
}
}
public static function returnValueFromKeyPath(array $param_PathAsArray, array $param_Array) {
$searcharray = $param_Array;
foreach($param_PathAsArray as $key) {
if(is_array($searcharray)) {
if(array_key_exists($key, $searcharray)) {
$searcharray = $searcharray[$key];
}
} else {
return false;
}
}
return $searcharray;
}
public static $ARRAY_PATTERN = '_#_';
/**
* transformiert Array mit speziellen String Key zu einem normalen Key
*
* @param array param_Array -- Array welches transformiert wird
* @param string param_pattern -- Pattern für den Schlüssel (im Beispiel '_#_')
*
* Array
(
[bleibt] =>
[data_#_1_#_Subject] => kein Betreff
)
*
*
* Array
(
[bleibt] =>
[data] => Array
(
[1] => Array
(
[Subject] => kein Betreff
)
)
)
*/
public static function transformArrayWithStringKeyToNormalKey(array &$param_Array, $param_pattern=null) {
// D::show($param_Array, '$param_Array');
if(is_null($param_pattern)) {
$param_pattern = mcArray::$ARRAY_PATTERN;
}
$tmp_POST = array();
$tmp_Array = $param_Array;
foreach($tmp_Array as $post_key => $post_value) {
if(FALSE!=strpos($post_key, $param_pattern)) {
$tmp_POST[$post_key] = array();
$array_key = split($param_pattern, $post_key);
$tmp_POST_key = null;
$tmp_POST[$post_key][0] = array();
$count_array_key = count($array_key);
for($i=0; $i<$count_array_key; $i++) {
if(is_null($tmp_POST_key)) {
$tmp_POST_key = $array_key[$i];
}
if(!array_key_exists($array_key[$i], $tmp_POST[$post_key][$i])) {
$tmp_POST[$post_key][$i][$array_key[$i]] = array();
}
if($count_array_key == $i+1) {
$tmp_POST[$post_key][$i][$array_key[$i]] = $post_value;
} else {
$tmp_POST[$post_key][$i+1] =& $tmp_POST[$post_key][$i][$array_key[$i]];
}
}
mcArray::addArrayValueToArray($param_Array, $tmp_POST[$post_key][0]);
unset($param_Array[$post_key]);
} else {
$param_Array[$post_key] = $post_value;
}
}
}
/**
* fügt Tabelle mit Werten zu einer bestehenden Tabelle
*
* siehe phpunit/class_mcArray_PHPTest.inc.php
*
* @param array $param_Array
* @param <type> $param_ArrayValue
*/
public static function addArrayValueToArray(array &$param_Array, $param_ArrayValue) {
$value_key = array_keys($param_ArrayValue);
foreach ($value_key as $key) {
if(array_key_exists($key, $param_Array)) {
mcArray::addArrayValueToArray($param_Array[$key], $param_ArrayValue[$key]);
} else {
$param_Array[$key] = $param_ArrayValue[$key];
}
}
}
}
?>