-
Notifications
You must be signed in to change notification settings - Fork 0
/
highscore.php
41 lines (29 loc) · 1.03 KB
/
highscore.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
<?php
function sortEntries($entry, $entry2) {
if ((int) $entry['score'][0] == (int) $entry2['score'][0])
return 0;
return ((int) $entry['score'][0] < (int) $entry2['score'][0]) ? 1 : -1;
}
$highscore = simplexml_load_file("highscore.xml");
if ($_POST['score'] !== null) {
$newEntry = $highscore->addChild("entry");
$newEntry->addAttribute('name', $_POST['name']);
$newEntry->addAttribute('score', $_POST['score']);
$newEntry->addAttribute('date', date("d.m.y - H:i:s"));
$highscore->saveXML("highscore.xml");
} else {
$highscoreArray = array();
foreach($highscore->entry as $entry)
$highscoreArray[] = $entry;
usort($highscoreArray, "sortEntries");
$counter = 1;
foreach($highscoreArray as $entry) {
echo "<tr>";
echo "<td>" . $counter . "</td>";
echo "<td>" . $entry['name'] . "</td>";
echo "<td>" . $entry['score'] . "</td>";
echo "<td>" . $entry['date'] . "</td>";
echo "</tr>";
$counter++;
}
}