class_mcArray.inc.php
2.67 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
<?php
/**
* @todo
* könnte in
* SEOLinkCache eingesetzt werden
*/
class mcArray {
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];
}
}
}
}
?>