Convert the ZIP code from Singapore to the corresponding region-php Tutorial

Source: Internet
Author: User
Convert the ZIP code from Singapore to the corresponding region
<无详细内容>

  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. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.