$countries = array ( "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 🙂
What have you tried?
$lastcountry = ''; foreach($coutries as $id=>$country) { $cityset = explode(',', $country) if($ityset[1] == $lastcountry) { echo $cityset[0]."<br />"; } else { $lastcountry = $cityset[1]; echo "-".$cityset[1]."<br />".$cityset[0]."<br />"; } }