3v4l.org

run code in 200+ PHP versions simultaneously
<?php function alphabetize_custom($a, $b, $alphabet = " -,.ȝjʿwbpfmnrhḥḫẖsšqkgtṯdḏ⸗/()[]<>{}'*#I0123456789&@%", $encoding = 'UTF-8') { //echo "\n----\n$a =vs= $b"; $mb_length = max(mb_strlen($a, $encoding), mb_strlen($b, $encoding)); for ($i = 0; $i < $mb_length; ++$i) { //echo "\n"; $a_char = mb_substr($a, $i, 1, $encoding); $b_char = mb_substr($b, $i, 1, $encoding); //echo "$a_char -vs- $b_char\n"; //echo "(" , mb_strlen($a_char, $encoding), " & ", mb_strlen($b_char, $encoding), ")\n"; if ($a_char === $b_char) {/*echo "identical, continue";*/ continue;} if (!mb_strlen($a_char, $encoding)) { /* echo "a is empty -1";*/ return -1;} if (!mb_strlen($b_char, $encoding)) { /*echo "b is empty 1";*/ return 1;} $a_offset = mb_strpos($alphabet, $a_char, 0, $encoding); $b_offset = mb_strpos($alphabet, $b_char, 0, $encoding); //echo "[" , $a_offset, " & ", $b_offset, "]\n"; if ($a_offset == $b_offset) { /*echo "== offsets, continue";*/ continue;} if ($a_offset < $b_offset) { /*echo "a offset -1";*/ return -1;} //echo "b offset 1"; return 1; } //echo "0"; 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 ev85t
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', ), )