Sort comma separated list Alphabetically PHP -


i have data in php variable in comma separated list. here data (some part of save space)

$xyz="europe, france, italy, spain, uk, us,nordic, west europe, belgium, luxembourg, netherlands, sweden,us,asia, europe, israel, north america, india,north america, , china, hong kong,west north central, west south central,uk,east south central,middle atlantic, greater china, malaysia, singapore, taiwan, middle atlantic, global, australasia, central , east europe"; 

i want sort alphabetically. manually tedious there easier way this?

kind regards, ahmar

i pasting snippet doing:

  1. splicing string
  2. remove blank spaces on each element
  3. remove empty elements
  4. sorting array
  5. printing result

i hope usefull you

<?php $xyz = "europe, france, italy, spain, uk, us,nordic, west europe, belgium, luxembourg, netherlands, sweden,us,asia, europe, israel, north america, india,north america, , china, hong kong,west north central, west south central,uk,east south central,middle atlantic, greater china, malaysia, singapore, taiwan, middle atlantic, global, australasia, central , east europe"; $array = array_filter(array_map('trim', explode(',', $xyz))); asort($array); $array = implode(', ', $array); print_r($array); 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -