Skip to content

Instantly share code, notes, and snippets.

@rootindex
Created January 9, 2017 15:18
Show Gist options
  • Save rootindex/a6b815ee2313724c51f48c6c50501ab2 to your computer and use it in GitHub Desktop.
Save rootindex/a6b815ee2313724c51f48c6c50501ab2 to your computer and use it in GitHub Desktop.
<?php
$postcode = $argv[1];
$regionMap = [
'EC' => [
['4731', '5199'],
['5200', '5299'],
['5300', '5499'],
['5500', '5999'],
['6000', '6099'],
['6100', '6499'],
],
'FS' => [
['9300', '9399'],
['9400', '9699'],
['9700', '9899'],
['9900', '9999'],
],
'GT' => [
['0001', '0299'],
['1400', '1699'],
['1700', '1799'],
['1800', '1999'],
['2000', '2199'],
],
'NL' => [
['2900', '3199'],
['3200', '3299'],
['3300', '3599'],
['3600', '3799'],
['3800', '3999'],
['4000', '4099'],
['4100', '4299'],
['4300', '4499'],
['4500', '4730'],
],
'LP' => [
['0500', '0698'],
['0699', '0999'],
],
'MP' => [
['1000', '1399'],
['2200', '2499'],
],
'NC' => [
['8100', '8100'],
['8300', '8799'],
['8800', '8999'],
],
'NW' => [
['0300', '0499'],
['2500', '2899'],
],
'WC' => [
['6500', '6699'],
['6700', '6899'],
['6900', '7099'],
['7100', '7299'],
['7300', '7399'],
['7400', '7599'],
['7600', '7699'],
['7700', '8099'],
]
];
$postcode = (int)$postcode;
// if empty return null
if ($postcode === 0) {
echo "failed";
}
foreach ($regionMap as $province => $provinceCodes) {
foreach ($provinceCodes as $code) {
if ($postcode >= (int)$code[0] && $postcode <= (int)$code[1]) {
echo $province . PHP_EOL;
}
}
}
echo "failed";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment