I had a look at it and figured it was a lot of hassle to go to every time you wanted to do what amounts to a table lookup.
Dunno if it's too long to run properly, but certainly looks too long to debug by eye... It's a lot of stuff to go through every time as well; it might be better to do it once (each time the mapping changes) and store the results in an array which can be included when needed.
I'll call the array $zone_mappings. It contains 1000 elements, numbered 0 to 999.
First, create it and fill it in; like I say, this only needs to be done once, by some sort of administration script.
for($zip=0; $zip<1000; $zip++) $zone_mappings[$zip]=0;
for($zip=5; $zip<=98; $zip++) $zone_mappings[$zip]=8;
for($zip=100; $zip<=212; $zip++) $zone_mappings[$zip]=8;
for($zip=214; $zip<=268; $zip++) $zone_mappings[$zip]=8;
....
...
..
.
for($zip=919; $zip<=921; $zip++) $zone_mappings[$zip]=1;
And so on and so forth for the whole thing.
Now the administration script writes it out. Easiest is to create a PHP file which can be included whenever $zone_mappings is needed.
fwrite($zm_file, '$zone_mappings = array(';
foreach($zip=0; $zip<1000; $zip++)
{ fwrite($zm_file,$zone_mappings[$zip].',');
if($zip%10==9)
fwrite($zm_file,"\n");
}
fwrite($zm_file, ");\n");
Yes, it leaves a trailing comma on the end of the array; PHP doesn't appear to mind.
Finally, use it.
include('zone_mappings.php');
$zipcode=$_POST['zipcode'];
if(strlen($zipcode)==5)
{ $zip = substr($zipcode,0,3);
$zone = $zone_mappings[$zip];
}
Now I haven't run or tested any of that - I'm not on my own time right now 😉