Skip to content

Instantly share code, notes, and snippets.

@Committing
Last active March 8, 2022 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Committing/6c6433539b896f4a8489c87ec0a0554b to your computer and use it in GitHub Desktop.
Save Committing/6c6433539b896f4a8489c87ec0a0554b to your computer and use it in GitHub Desktop.
Ducky/Rich/Adem's homework
<?php
ini_set('memory_limit', -1);
set_time_limit(800);
include_once('functions.php');
$fileName = "2018.csv";
$resourceReader = fopen($fileName, 'r');
$output = array();
$return = array();
$allowed_types = array(
'TMAX',
'TMIN'
);
$whitelisted_ids = array(
'UK000056225',
'UK000003377'
);
while (($row = fgetcsv($resourceReader)) !== FALSE) {
$id = $row[0];
$date = $row[1];
$type = $row[2];
$value = $row[3];
if (in_array($type, $allowed_types) && in_array($id, $whitelisted_ids)) {
$key = $id . $date;
$output[$key]['id'] = $id;
$output[$key]['date'] = $date;
$output[$key][$type] = $value;
if ( isset($output[$key]['TMAX']) && is_numeric($output[$key]['TMAX'])
&& isset($output[$key]['TMIN']) && is_numeric($output[$key]['TMIN'])) {
$return[$key] = $output[$key]['diff'] = $output[$key]['TMAX'] - $output[$key]['TMIN'];
}
}
}
pr($return);
die;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment