From 9a45325b16d6731f1c7755fa9a1a11cd19ea408d Mon Sep 17 00:00:00 2001 From: Toby Phipps Date: Mon, 7 Oct 2019 22:38:56 -0700 Subject: [PATCH] Enable arrays for State and County codes allowing multiple spellings and/or translations --- src/Formatter.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Formatter.php b/src/Formatter.php index 27ba97d..b77e220 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -425,8 +425,17 @@ private function addCode($type, $addressArray) if ($type === 'state') { if (array_key_exists($addressArray['country_code'], $this->stateCodes)) { foreach($this->stateCodes[$addressArray['country_code']] as $key => $val) { - if (strtoupper($addressArray['state']) == strtoupper($val)) { - $addressArray['state_code'] = $key; + if(is_array($val)) { + foreach($val as $state) { + if (strtoupper($addressArray['state']) == strtoupper($state)) { + $addressArray['state_code'] = $key; + } + } + } + else { + if (strtoupper($addressArray['state']) == strtoupper($val)) { + $addressArray['state_code'] = $key; + } } } @@ -456,8 +465,17 @@ private function addCode($type, $addressArray) } elseif ($type === 'county') { if (array_key_exists($addressArray['country_code'], $this->countyCodes)) { foreach($this->countyCodes[$addressArray['country_code']] as $key => $val) { - if (strtoupper($addressArray['county']) == strtoupper($val)) { - $addressArray['county_code'] = $key; + if(is_array($val)) { + foreach($val as $county) { + if (strtoupper($addressArray['county']) == strtoupper($county)) { + $addressArray['county_code'] = $key; + } + } + } + else { + if (strtoupper($addressArray['county']) == strtoupper($val)) { + $addressArray['county_code'] = $key; + } } } }