3v4l.org

run code in 300+ PHP versions simultaneously
<?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"; }
Output for 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.14
Aa, Az, B, C, X, Za, aa, aa, az, az, b, b, c, c, x, x, za, za, ß, ß, ß, ä, ä, ä, ñ, ñ, ñ, ü, ü, ü # usort + strcmp aa, Aa, aa, az, Az, az, b, B, b, c, C, c, x, X, x, za, Za, za, ß, ß, ß, ä, ä, ä, ñ, ñ, ñ, ü, ü, ü # usort + strcasecmp Aa, Az, B, C, X, Za, aa, aa, az, az, b, b, c, c, x, x, za, za, ß, ß, ß, ä, ä, ä, ñ, ñ, ñ, ü, ü, ü # sort

preferences:
56.61 ms | 407 KiB | 5 Q