Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<?php
$fh = fopen(__DIR__ . '/1040818.csv', 'r');
$counter = array();
while ($line = fgetcsv($fh, 2048)) {
if ($line[0] === '確定日期') {
//empty vars
$currentArea = '';
$currentDay = '';
} elseif (!empty($line[3])) {
if (empty($currentDay)) {
$dayParts = explode('/', $line[0]);
$currentDay = implode('-', array(
2015,
str_pad(intval($dayParts[1]), 2, '0', STR_PAD_LEFT),
str_pad(intval($dayParts[2]), 2, '0', STR_PAD_LEFT),
));
}
if (!empty($line[1])) {
$currentArea = $line[1];
}
$cPos = strpos($line[2], '(');
if (false !== $cPos) {
$line[2] = substr($line[2], 0, $cPos);
}
$key = "{$currentArea}{$line[2]}";
if (!isset($counter[$key])) {
$counter[$key] = array(
'total' => $line[3],
'logs' => array(),
);
} else {
$counter[$key]['total'] += $line[3];
}
$counter[$key]['logs'][] = array(
$currentDay,
$line[3],
);
//echo "{$currentDay} - {$currentArea} - {$line[2]} : +{$line[3]}\n";
}
}
print_r($counter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment