Posted By

olive on 08/24/06


Tagged

divers


Versions (?)

Trouver la région à laquelle appartient un département


 / Published in: PHP
 

  1. $liste_regions = array (
  2. "Alsace" => array(67,68),
  3. "Aquitaine" => array(24,33,40,47,64),
  4. "Auvergne" => array ("03",15,43,63),
  5. "Basse-Normandie" => array (14,50,61),
  6. "Bourgogne" => array (21,58,71,89),
  7. "Bretagne" => array (22,29,35,56),
  8. "Centre" => array (18,28,36,37,41,45),
  9. "Champagne-Ardenne" => array ("08",10,51,52),
  10. "Corse" => array(20),
  11. "DOM-TOM" => array(97),
  12. "Franche-Comté" => array (25,39,70,90),
  13. "Haute-Normandie" => array (27,76),
  14. "Ile de France" => array(75,77,78,91,92,93,94,95),
  15. "Languedoc-Roussillon" => array(11,30,34,48,66),
  16. "Limousin" => array(19,23,87),
  17. "Lorraine" => array (54,55,57,88),
  18. "Midi-Pyrénées" => array("09",12,31,32,46,65,81,82),
  19. "Nord / Pas-de-Calais" => array(59,62),
  20. "Pays de la Loire" => array (44,49,53,72,85),
  21. "Picardie" => array ("02",60,80),
  22. "Poitou-Charentes" => array (16,17,79,86),
  23. "PACA" => array("04","05","06",13,83,84),
  24. "Rhône-Alpes" => array ("01","07",26,38,42,69,73,74)
  25. );
  26.  
  27. // Renvoie la région à partir du code postal ou du numéro de département
  28. function region($codepostal)
  29. {
  30. global $liste_regions;
  31. $departement = substr($codepostal,0,2);
  32.  
  33. foreach($liste_regions as $region => $liste_dep)
  34. {
  35. if (in_array($departement, $liste_dep))
  36. {
  37. return $region;
  38. }
  39. }
  40. }
  41. print region(35170);
  42. // Renvoie Bretagne

Report this snippet  

You need to login to post a comment.