fork download
  1. <?php
  2.  
  3. /* init in costruct */
  4. function getCountry() { return 'Country'; }
  5. function getRegion() { return 'Region'; }
  6. function getCity() { return 'City'; }
  7. function getZipCode() { return 'ZipCode'; }
  8. function getStreet() { return 'Street'; }
  9. function getHouseNumber(){ return 'HouseNumber'; }
  10. function getBuilding() { return 'Building'; }
  11. function getAppartment() { return 'Appartment'; }
  12.  
  13. /* init in costruct */
  14. $func = array(
  15. 'country' => array('getCountry', 'Customer address info: ' ),
  16. 'region' => array('getRegion', ', ' ),
  17. 'city' => array('getCity', ', ' ),
  18. 'zipCode' => array('getZipCode', ', ' ),
  19. 'street' => array('getStreet', ', ' ),
  20. 'houseNumber' => array('getHouseNumber', ', ' ),
  21. 'building' => array('getBuilding', ', корп. ' ),
  22. 'appartment' => array('getAppartment', ', кв. ' )
  23. );
  24.  
  25. function getAddresInfo($cfg)
  26. {
  27. global $func;
  28. $CustomerAddrInfo = '';
  29.  
  30. foreach ($cfg as $key=>$val) {
  31. if ($val == '1')
  32. $cfg[$key] = $func[$key][0]();
  33.  
  34. $CustomerAddrInfo .= (!empty($cfg[$key]))? $func[$key][1] . $cfg[$key] : '';
  35. }
  36. return $CustomerAddrInfo;
  37. }
  38.  
  39. /* config argument for getAddresInfo($cfg) */
  40. $addressInfo = array(
  41. 'country' => '1',
  42. 'region' => '1',
  43. 'city' => '1',
  44. 'zipCode' => '1',
  45. 'street' => '1',
  46. 'houseNumber' => '1',
  47. 'building' => '1',
  48. 'appartment' => '1'
  49. );
  50.  
  51. echo getAddresInfo($addressInfo);
  52. $addressInfo['appartment'] = '0';
  53. echo "\n";
  54. echo getAddresInfo($addressInfo);
  55. echo "\n";
  56. $addressInfo['building'] = '0';
  57. echo getAddresInfo($addressInfo);
  58. ?>
Success #stdin #stdout 0.02s 13064KB
stdin
Standard input is empty
stdout
Customer address info: Country, Region, City, ZipCode, Street, HouseNumber, корп. Building, кв. Appartment
Customer address info: Country, Region, City, ZipCode, Street, HouseNumber, корп. Building
Customer address info: Country, Region, City, ZipCode, Street, HouseNumber