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:
- splicing string
- remove blank spaces on each element
- remove empty elements
- sorting array
- 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
Post a Comment