PHP-ZipCode-Class icon indicating copy to clipboard operation
PHP-ZipCode-Class copied to clipboard

Original Zip Code being used is skipped by getZipsInRange

Open bigmike7801 opened this issue 12 years ago • 2 comments

Let's say for example I create a new instance of Zipcode and then loop through those results by doing:

$zip = new Zipcode("98674");

foreach ($zip->getZipsInRange(0, 15) as $k => $v) { $zip_codes[] = sprintf($v); //print_r($v); }

The original zip code being searched of 98674 isn't returned with the results.

bigmike7801 avatar Apr 29 '13 14:04 bigmike7801

Hello,

I don't remember why I started doing this... if it was in a doc or comment I read, or if I just noticed it...

I always add the zip I'm searching on to the array before I start.

Here the array $zipList is initialized with only 1 value, the search zip... then a foreach to add all the nearby zips

$zipStuff = new ZipCode($data['zip'], $dbh);

$zipList = array($data['zip']); // start with the array only containing the search zip! foreach ($zipStuff->getZipsInRange(0, $data['distanceMenu']) as $miles=>$zip) { $zipList[] = $zip;

$zipDistance[$zip->getZip()] = round($miles + 0, 1);

}

Jay

JayLevine avatar Apr 29 '13 18:04 JayLevine

I too am using that workaround, but just found it strange that the originating zip wasn't included in the results.

bigmike7801 avatar Apr 29 '13 18:04 bigmike7801