Skip to content

Instantly share code, notes, and snippets.

@tamakiii
Created October 20, 2015 17:28
Show Gist options
  • Save tamakiii/6f7dc58507e99655a60b to your computer and use it in GitHub Desktop.
Save tamakiii/6f7dc58507e99655a60b 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 timeFilterYield(array $reports, $start, $end)
{
$start = strtotime($start);
$end = strtotime($end);
foreach ($reports as $report) {
$current = strtotime($report[KEY_DATE]) ;
if ($start <= $current && $current < $end) {
yield $report;
}
}
}
$filepath = $argv[1];
$csv = array_filter(explode(PHP_EOL, file_get_contents($filepath)));
$reports = array_map('str_getcsv', $csv);
iterator_to_array(timeFilterYield($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