3v4l.org

run code in 200+ PHP versions simultaneously
<?php function alphabetize_custom($a, $b) { $alphabet = [' ', '-', ',', '.', 'ȝ', 'j', 'ʿ', 'w', 'b', 'p', 'f', 'm', 'n', 'r', 'h', 'ḥ', 'ḫ', 'ẖ', 's', 'š', 'q', 'k', 'g', 't', 'ṯ', 'd', 'ḏ', '⸗', '/', '(', ')', '[', ']', '<', '>', '{', '}', "'", '*', '#', 'I', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '&', '@', '%']; unset($alphabet[0]); // removes dummy first key, effectively starting the keys from 1 $encoding = 'UTF-8'; $mb_length = max(mb_strlen($a, $encoding), mb_strlen($b, $encoding)); for ($i = 0; $i < $mb_length; ++$i) { $a_char = mb_substr($a, $i, 1, $encoding); $b_char = mb_substr($b, $i, 1, $encoding); if ($a_char === $b_char) continue; $a_key = array_search($a_char, $alphabet); $b_key = array_search($b_char, $alphabet); if ($a_key === $b_key) continue; return $a_key - $b_key; } return 0; } $result = [ "nṯr" => ["Ka.C.Coptite.urkVIII,176b", "Ka.C.Coptite.urkVIII,177,1"], "n" => ["Ka.C.Coptite.urkVIII,176c", "Ka.C.Coptite.urkVIII,177,1", "Ka.C.Coptite.urkVIII,177,2"], "nḫȝḫȝ" => ["Ka.C.Coptite.urkVIII,176c"], "nwj" => ["Ka.C.Coptite.urkVIII,176c"], "nfr" => ["Ka.C.Coptite.urkVIII,176c", "Ka.C.Coptite.urkVIII,177,2"], "nḥḥ" => ["Ka.C.Coptite.urkVIII,176e", "Ka.C.Coptite.urkVIII,177,1", "Ka.C.Coptite.urkVIII,177,1"], "nḏ" => ["Ka.C.Coptite.urkVIII,177,1"] ]; uksort($result, 'alphabetize_custom'); var_export($result);
based on 7OvdH
Output for 5.6.0 - 7.4.0
array ( 'n' => array ( 0 => 'Ka.C.Coptite.urkVIII,176c', 1 => 'Ka.C.Coptite.urkVIII,177,1', 2 => 'Ka.C.Coptite.urkVIII,177,2', ), 'nwj' => array ( 0 => 'Ka.C.Coptite.urkVIII,176c', ), 'nfr' => array ( 0 => 'Ka.C.Coptite.urkVIII,176c', 1 => 'Ka.C.Coptite.urkVIII,177,2', ), 'nḥḥ' => array ( 0 => 'Ka.C.Coptite.urkVIII,176e', 1 => 'Ka.C.Coptite.urkVIII,177,1', 2 => 'Ka.C.Coptite.urkVIII,177,1', ), 'nḫȝḫȝ' => array ( 0 => 'Ka.C.Coptite.urkVIII,176c', ), 'nṯr' => array ( 0 => 'Ka.C.Coptite.urkVIII,176b', 1 => 'Ka.C.Coptite.urkVIII,177,1', ), 'nḏ' => array ( 0 => 'Ka.C.Coptite.urkVIII,177,1', ), )