-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
163 lines (58 loc) · 1.55 KB
/
test.php
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
<?php
function escaped_explode($string){
$r=[];
$stream = fopen('php://memory','r+');
fwrite($stream, $string);
rewind($stream);
while (($data = fgetcsv($stream,0,chr(44),chr(34))) !== FALSE)
$r=array_merge($r,$data);
fclose($stream);
return $r;
}
$myfile = fopen("data.csv","r");
$skola_examens = [];
$columns = [];
$rows = [];
while(!feof($myfile)) {
$arr = escaped_explode(fgets($myfile), ',');
$SKOLA = $arr[2];
$EXAMENS = $arr[1];
$PUNKTI = $arr[3];
array_push($columns, $EXAMENS);
array_push($rows, $SKOLA);
if(!isset($skola_examens[$SKOLA]) ) {
$examens_punkti = [];
$skola_examens[$SKOLA] = $examens_punkti;
} else {
$examens_punkti = $skola_examens[$SKOLA];
}
$examens_punkti[$EXAMENS] = $PUNKTI;
$skola_examens[$SKOLA] = $examens_punkti;
}
fclose($myfile);
$rows = array_unique($rows);
$columns = array_unique($columns);
/*
foreach($skola_examens as $key => $value) {
print("> " . $key . "<br/>");
foreach($value as $k => $v) {
print(" >>> " . $k . " >>> " . $v . "<br/>");
}
}*/
print("<br/>");
print(",");
foreach($columns as $col) {
print("\"" . $col . "\", ");
}
foreach($rows as $row) {
print("<br/> \"". $row . "\", ");
$examens_punkti = $skola_examens[$row];
foreach($columns as $col) {
if(isset($examens_punkti[$col]) ) {
$punkti = $examens_punkti[$col];
print($punkti );
}
print(", ");
}
}
?>