-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCSV.php
39 lines (31 loc) · 987 Bytes
/
CSV.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
<?php
Class BlackJackCSV
{
private static $points = array();
public static function add( $id, $player, $balance )/*{{{*/
{
@self::$points[$id][$player] = $balance;
}/*}}}*/
public static function store( $file )
{
$csv = array();
$playerNames = array();
foreach ( self::$points[0] as $player => $data )
$playerNames[] = $player;
$csv[] =';' . implode(';', $playerNames );
foreach ( self::$points as $id => $players )
{
$tmp = '';
$tmp .= $id .';';
foreach ( $playerNames as $name )
{
if ( array_key_exists($name, $players ) )
$tmp .= $players[$name] .';';
else
$tmp .= 0 .';';
}
$csv[] = $tmp;
}
file_put_contents( $file, implode("\n", $csv ) );
}
}