Is it possible to sort an array with Unicode / UTF-8 characters in PHP using a natural order algorithm? For example (the order in this array is correctly ordered):
I struggled with asort with this issue.
Sorting:
Array
(
[xa] => África
[xo] => Australasia
[cn] => China
[gb] => Reino Unido
[us] => Estados Unidos
[ae] => Emiratos Árabes Unidos
[jp] => Japón
[lk] => Sri Lanka
[xe] => Europa Del Este
[xw] => Europa Del Oeste
[fr] => Francia
[de] => Alemania
[be] => Bélgica
[nl] => Holanda
[es] => España
)
put África at the end. I solved it with this dirty little piece of code (which is fit for my purpose and my timeframe):
$sort = array();
foreach($retval AS $key => $value) {
$v = str_replace('ä', 'a', $value);
$v = str_replace('Ä', 'A', $v);
$v = str_replace('Á', 'A', $v);
$v = str_replace('é', 'e', $v);
$v = str_replace('ö', 'o', $v);
$v = str_replace('ó', 'o', $v);
$v = str_replace('Ö', 'O', $v);
$v = str_replace('ü', 'u', $v);
$v = str_replace('Ü', 'U', $v);
$v = str_replace('ß', 'S', $v);
$v = str_replace('ñ', 'n', $v);
$sort[] = "$v|$key|$value";
}
sort($sort);
$retval = array();
foreach($sort AS $value) {
$arr = explode('|', $value);
$retval[$arr[1]] = $arr[2];
}