"london,united kingdom,",
"manchester,united kingdom",
"madrid,spain",
"lisbon,portugal"
);
With the array above, I would like to display the following
-united kingdom
london
manchester
-spain
madrid
-portugal
lisbon
thanks
Moderator: General Moderators
Code: Select all
$countries = Array(
"United Kingdom" => Array(
"Manchester",
"London"
),
// an so on
)Code: Select all
$countries = array (
"london,united kingdom,",
"manchester,united kingdom",
"madrid,spain",
"lisbon,portugal"
);
$country_city = array();
foreach($countries as $city_string) {
list($city, $country) = explode(',', $city_string,2);
$country_city[$country][] = $city;
}