Advertisement
Guest User

Untitled

a guest
Nov 8th, 2013
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. function area_by_country( $selected_country ) {
  2.  
  3. $get_locations = get_field( 'location_maps', 'options' ); // Get all locations from options
  4. $get_southarea = get_field( 'location_sa_maps', 'options'); // Get South Africa areas from options
  5. $get_southcity = get_field( 'south_africa_cities', 'options'); // Get South Africa cities from options
  6.  
  7. // Extract only areas from list of South Africa
  8. foreach( $get_southarea as $southarea ) {
  9. $southareas[] = $southarea['sa_area'];
  10. }
  11.  
  12. // Convert South Africa areas from array to comma separated list
  13. $africa_areas = implode( ', ', $southareas);
  14.  
  15. // Convert South Africa to same array as other locations
  16. $south_africa = array(
  17. 'area' => 'South Africa',
  18. 'areas' => $africa_areas,
  19. 'cities' => $get_southcity,
  20. );
  21.  
  22. // Push South Africa to main array of all other countries
  23. array_push( $get_locations, $south_africa );
  24.  
  25. // Simplify array of all countries
  26. foreach ( $get_locations as $key => $value ) {
  27.  
  28. $country_list[$value['area']] = array(
  29. 'map' => $value['map'],
  30. 'area' => $value['areas'],
  31. 'city' => $value['cities']
  32. );
  33. }
  34.  
  35. // Returns Area and City by Country selected
  36. if (array_key_exists( $selected_country, $country_list)) {
  37.  
  38. $arr_areas = explode( ', ', $country_list[$selected_country]['area'] );
  39. $arr_cities = explode( ', ', $country_list[$selected_country]['cities'] );
  40.  
  41. printaj( $arr_areas );
  42. printaj( $arr_cities );
  43.  
  44. }
  45.  
  46. return $arr_areas;
  47.  
  48. die();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement