mb_internal_encoding("UTF-8");
$array1 = array('aümg', 'abc', 'aécas', 'bdö', 'äsasf', 'aäfa');
uasort($array1, 'utf_8_german::cmp');
var_dump($array3);
Result: array(6) { [5]=> string(5) "aäfa" [1]=> string(3) "abc" [2]=> string(6) "aécas" [0]=> string(5) "aümg" [4]=> string(6) "äsasf" [3]=> string(4) "bdö" }
class utf_8_german{
// everything else is sorted at the end
static $order = '0123456789AaÄäBbCcDdEeéFfGgHhIiJjKkLlMm
NnOoÖöPpQqRrSsßTtUuÜüVvWwXxYyZz';
static $char2order;
static function cmp($a, $b) {
if($a == $b){
return 0;
}
if (empty(self::$char2order)){
$order = 1;
$len = mb_strlen(self::$order);
for ($order=0; $order<$len; ++$order){
self::$char2order[mb_substr(self::$order, $order, 1)] = $order;
}
}
$len_a = mb_strlen($a);
$len_b = mb_strlen($b);
$max=min($len_a, $len_b);
for($i=0; $i<$max; ++$i){
$char_a= mb_substr($a, $i, 1);
$char_b= mb_substr($b, $i, 1);
if ($char_a == $char_b) continue;
$order_a = (isset(self::$char2order[$char_a])) ? self::$char2order[$char_a] : 9999;
$order_b = (isset(self::$char2order[$char_b])) ? self::$char2order[$char_b] : 9999;
return ($order_a < $order_b) ? -1 : 1;
}
return ($len_a < $len_b) ? -1 : 1;
}
}