<?php
// Yes we can use special chars in identifiers!
class ñßü {}
$chars = ['aa', 'az', 'b', 'c', 'x', 'za', 'ä', 'ü', 'ß', 'ñ'];
// Put the lowercase chars twice to identify if they have equal weight.
$chars = [...$chars, ...array_map(ucfirst(...), $chars), ...$chars];
foreach ([
'usort + strcmp' => fn (&$arr) => usort($arr, strcmp(...)),
'usort + strcasecmp' => fn (&$arr) => usort($arr, strcasecmp(...)),
'sort' => sort(...),
] as $name => $sortfunction) {
$chars_sorted = $chars;
$sortfunction($chars_sorted);
print implode(', ', $chars_sorted) . " # $name\n";
}
preferences:
34.44 ms | 410 KiB | 5 Q