Thread [php] Präfixe aus Liste herausarbeiten (6 answers)
Opened by tim at 2012-11-05 11:33

GwenDragon
 2013-03-04 14:13
#166208 #166208
User since
2005-01-17
14760 Artikel
Admin1
[Homepage]
user image
Ungetestet:
Code: (dl )
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
$data = array(
'123456',
'123457'
);


$new = array();
$data_tmp = $new;

while (1) {
$test = array();
$new = array();

foreach ($data_tmp as $item) {
if (preg_match('/^\d{2,}/',$item) ) {
$suffix = substr($item,0,length($item)-1);
$test[$item][$suffix]+=1;
}
}

foreach (array_keys($test) as $base) {
if (count(array_keys($test[$base])) == 10) {
array_push($new, $base);
}
else {
foreach (array_keys($test[$base]) as $k) {
array_push($new, $base . $k);
}
}
if (count($new) == count($data_tmp)) {
goto leavewhile;
}
$data_tmp = $new;
}
leavewhile:

foreach (sort($new) as $val) {
echo $val . "\n";
}

View full thread [php] Präfixe aus Liste herausarbeiten