See this code:
<?php $arr = array('wr' => 1, 'wrS' => 6, 'wr,w' => 3, 'wr.w' => 4, 'wr-qA' => 2, 'wrs' => 5); function compare_by_alphabet(array $alphabet, $str1, $str2) { $l1 = strlen($str1); $l2 = strlen($str2); $c = min($l1, $l2); for ($i = 0; $i < $c; $i++) { $s1 = $str1[$i]; $s2 = $str2[$i]; if ($s1===$s2) continue; $i1 = array_search($s1, $alphabet); if ($i1===false) continue; $i2 = array_search($s2, $alphabet); if ($i2===false) continue; if ($i2===$i1) continue; if ($i1 < $i2) return -1; else return 1; } if ($l1 < $l2) return -1; elseif ($l1 > $l2) return 1; return 0; } function compare_keys_by_alphabet($a, $b) { static $alphabet = array('-', ',', '.', 'A', 'j', 'a', 'w', 'b', 'p', 'f', 'm', 'n', 'r', 'h', 'H', 'x', 'X', 's', 'S', 'q', 'ββk', 'g', 't', 'T', 'd', 'D', '=', '/', '(', ')', '[', ']', '<', '>', '{', '}', '\'', '*', '#', 'I', 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '&', '@'); return compare_by_alphabet($alphabet, $a, $b); } uksort($arr, 'compare_keys_by_alphabet'); print_r($arr);
Result:
Array ( [wr] => 1 [wr-qA] => 2 [wr,w] => 3 [wr.w] => 4 [wrs] => 5 [wrS] => 6 )