Convert Singapore's postal code to the corresponding region

WBOY
Release: 2016-07-25 09:11:10
Original
2856 people have browsed it
  1. //Example
  2. dco_get_district("160149");
  3. /* ##################################
  4. CONVERT POSTAL CODE TO DISTRICT NUMBER AND NAME
  5. ################################## */
  6. function dco_get_district($postal) {
  7. //Define the 28 Districts
  8. $districts = array(
  9. 'D01 City - Business District'=>array(
  10. '01',
  11. '02',
  12. '03',
  13. '04',
  14. '05',
  15. '06'
  16. ),
  17. 'D02 City - Business District'=>array(
  18. '07',
  19. '08'
  20. ),
  21. 'D03 Central South'=>array(
  22. '14',
  23. '15',
  24. '16'
  25. ),
  26. 'D04 South'=>array(
  27. '09',
  28. '10'
  29. ),
  30. 'D05 South West'=>array(
  31. '11',
  32. '12',
  33. '13'
  34. ),
  35. 'D06 City - Business District'=>array(
  36. '17'
  37. ),
  38. 'D07 City'=>array(
  39. '18',
  40. '19'
  41. ),
  42. 'D08 Central'=>array(
  43. '20',
  44. '21'
  45. ),
  46. 'D09 Central - Orchard'=>array(
  47. '22',
  48. '23'
  49. ),
  50. 'D10 Central - Near Orchard'=>array(
  51. '24',
  52. '25',
  53. '26',
  54. '27'
  55. ),
  56. 'D11 Central - Near Orchard'=>array(
  57. '28',
  58. '29',
  59. '30'
  60. ),
  61. 'D12 Central'=>array(
  62. '31',
  63. '32',
  64. '33'
  65. ),
  66. 'D13 Central East'=>array(
  67. '34',
  68. '35',
  69. '36',
  70. '37'
  71. ),
  72. 'D14 Central East'=>array(
  73. '38',
  74. '39',
  75. '40',
  76. '41'
  77. ),
  78. 'D15 East Coast'=>array(
  79. '42',
  80. '43',
  81. '44',
  82. '45'
  83. ),
  84. 'D16 Upper East Coast'=>array(
  85. '46',
  86. '47',
  87. '48'
  88. ),
  89. 'D17 Far East'=>array(
  90. '49',
  91. '50',
  92. '81'
  93. ),
  94. 'D18 Far East'=>array(
  95. '51',
  96. '52'
  97. ),
  98. 'D19 North East'=>array(
  99. '53',
  100. '54',
  101. '55',
  102. '82'
  103. ),
  104. 'D20 Central North'=>array(
  105. '56',
  106. '57'
  107. ),
  108. 'D21 Central West'=>array(
  109. '58',
  110. '59'
  111. ),
  112. 'D22 Far West'=>array(
  113. '60',
  114. '61',
  115. '62',
  116. '63',
  117. '64'
  118. ),
  119. 'D23 North West'=>array(
  120. '65',
  121. '66',
  122. '67',
  123. '68'
  124. ),
  125. 'D24 Far North West'=>array(
  126. '69',
  127. '70',
  128. '71',
  129. ),
  130. 'D25 Far North'=>array(
  131. '72',
  132. '73'
  133. ),
  134. 'D26 North'=>array(
  135. '77',
  136. '78'
  137. ),
  138. 'D27 Far North'=>array(
  139. '75',
  140. '76'
  141. ),
  142. 'D28 North East'=>array(
  143. '79',
  144. '80'
  145. )
  146. );
  147. //Districts are determined by first 2 digits of the postal code
  148. $firstTwoDigits = substr($postal, 0, 2);
  149. //Find corresponding district
  150. foreach( $districts as $districtName=>$digits )
  151. {
  152. foreach( $digits as $digit)
  153. {
  154. if( $digit == $firstTwoDigits)
  155. {
  156. return $districtName;
  157. }
  158. }
  159. }
  160. }
  161. ?>
复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template