- //Example
- dco_get_district("160149");
-
- /* ##################################
- CONVERT POSTAL CODE TO DISTRICT NUMBER AND NAME
- ################################## */
-
- function dco_get_district($postal) {
-
- //Define the 28 Districts
- $districts = array(
- 'D01 City - Business District'=>array(
- '01',
- '02',
- '03',
- '04',
- '05',
- '06'
- ),
- 'D02 City - Business District'=>array(
- '07',
- '08'
- ),
- 'D03 Central South'=>array(
- '14',
- '15',
- '16'
- ),
- 'D04 South'=>array(
- '09',
- '10'
- ),
- 'D05 South West'=>array(
- '11',
- '12',
- '13'
- ),
- 'D06 City - Business District'=>array(
- '17'
- ),
- 'D07 City'=>array(
- '18',
- '19'
- ),
- 'D08 Central'=>array(
- '20',
- '21'
- ),
- 'D09 Central - Orchard'=>array(
- '22',
- '23'
- ),
- 'D10 Central - Near Orchard'=>array(
- '24',
- '25',
- '26',
- '27'
- ),
- 'D11 Central - Near Orchard'=>array(
- '28',
- '29',
- '30'
- ),
- 'D12 Central'=>array(
- '31',
- '32',
- '33'
- ),
- 'D13 Central East'=>array(
- '34',
- '35',
- '36',
- '37'
- ),
- 'D14 Central East'=>array(
- '38',
- '39',
- '40',
- '41'
- ),
- 'D15 East Coast'=>array(
- '42',
- '43',
- '44',
- '45'
- ),
- 'D16 Upper East Coast'=>array(
- '46',
- '47',
- '48'
- ),
- 'D17 Far East'=>array(
- '49',
- '50',
- '81'
- ),
- 'D18 Far East'=>array(
- '51',
- '52'
- ),
- 'D19 North East'=>array(
- '53',
- '54',
- '55',
- '82'
- ),
- 'D20 Central North'=>array(
- '56',
- '57'
- ),
- 'D21 Central West'=>array(
- '58',
- '59'
- ),
- 'D22 Far West'=>array(
- '60',
- '61',
- '62',
- '63',
- '64'
- ),
- 'D23 North West'=>array(
- '65',
- '66',
- '67',
- '68'
- ),
- 'D24 Far North West'=>array(
- '69',
- '70',
- '71',
- ),
- 'D25 Far North'=>array(
- '72',
- '73'
- ),
- 'D26 North'=>array(
- '77',
- '78'
- ),
- 'D27 Far North'=>array(
- '75',
- '76'
- ),
- 'D28 North East'=>array(
- '79',
- '80'
- )
- );
-
- //Districts are determined by first 2 digits of the postal code
- $firstTwoDigits = substr($postal, 0, 2);
-
- //Find corresponding district
- foreach( $districts as $districtName=>$digits )
- {
- foreach( $digits as $digit)
- {
- if( $digit == $firstTwoDigits)
- {
- return $districtName;
- }
- }
- }
-
- }
-
- ?>
复制代码
|