Skip to content

Instantly share code, notes, and snippets.

@tamakiii
Created October 20, 2015 17:30
Show Gist options
  • Save tamakiii/ebe7a05c4a40238bf9d3 to your computer and use it in GitHub Desktop.
Save tamakiii/ebe7a05c4a40238bf9d3 to your computer and use it in GitHub Desktop.
<?php
define('KEY_ID', 0);
define('KEY_DATE', 1);
/**
* @param array $reports
* @param string $start
* @param string $end
* @return array
*/
function timeFilter(array $reports, $start, $end)
{
$start = strtotime($start);
$end = strtotime($end);
return array_filter($reports, function(array $report) use ($start, $end) {
$current = strtotime($report[KEY_DATE]) ;
return $start <= $current && $current < $end;
});
}
$filepath = $argv[1];
$csv = array_filter(explode(PHP_EOL, file_get_contents($filepath)));
$reports = array_map('str_getcsv', $csv);
timeFilter($reports, '2015-01-02', '2015-01-05');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment