Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. /**
  2. * @param $object object simplexml object array from iso ref list
  3. * @return array ISO country reference reformatted to an array
  4. */
  5. function reformat($object)
  6. {
  7. $array = $this->objectToArray($object);
  8. $finalarr = array();
  9. foreach ($array['iso_3166_country'] as $countryarr) {
  10. $country = $countryarr['@attributes']['code'];
  11. if (is_array($countryarr['iso_3166_subset'])) {
  12. if (!is_array($countryarr['iso_3166_subset']['iso_3166_2_entry'])) {
  13. foreach ($countryarr['iso_3166_subset'] as $isoarr) {
  14. foreach ($isoarr['iso_3166_2_entry'] as $state) {
  15. $code = $state['@attributes']['code'];
  16. $name = $state['@attributes']['name'];
  17. $finalarr[$code] = $name;
  18. }
  19. }
  20. } else {
  21. foreach ($countryarr['iso_3166_subset']['iso_3166_2_entry'] as $state) {
  22. $code = $state['@attributes']['code'];
  23. $name = $state['@attributes']['name'];
  24. $finalarr[$code] = $name;
  25. }
  26. }
  27. } else {
  28. $finalarr[$country] .= array();
  29. }
  30. }
  31. return $finalarr;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement