Sort an array with special characters in PHP

You defined your locale incorrectly in setlocale().

Change:

setlocale(LC_ALL,'es_ES.UTF-8');

To:

setlocale(LC_ALL,'es_ES');

Output:

Array ( [ar] => árabe [ko] => coreano [es] => español [fr] => francés ) 

Try sorting by translitterated names:

function compareASCII($a, $b) {
    $at = iconv('UTF-8', 'ASCII//TRANSLIT', $a);
    $bt = iconv('UTF-8', 'ASCII//TRANSLIT', $b);
    return strcmp($at, $bt);
}

uasort($lang, 'compareASCII');

print_r($lang);