3v4l.org

run code in 300+ 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);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3XYNG
function name:  (null)
number of ops:  9
compiled vars:  !0 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                   !0, <array>
   32     1        INIT_FCALL                                               'uksort'
          2        SEND_REF                                                 !0
          3        SEND_VAL                                                 'alphabetize_custom'
          4        DO_ICALL                                                 
   34     5        INIT_FCALL                                               'var_export'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function alphabetize_custom:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 20
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 37
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 20
Branch analysis from position: 55
Branch analysis from position: 20
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 50
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3XYNG
function name:  alphabetize_custom
number of ops:  57
compiled vars:  !0 = $a, !1 = $b, !2 = $alphabet, !3 = $encoding, !4 = $mb_length, !5 = $i, !6 = $a_char, !7 = $b_char, !8 = $a_key, !9 = $b_key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        ASSIGN                                                   !2, <array>
    4     3        UNSET_DIM                                                !2, 0
    5     4        ASSIGN                                                   !3, 'UTF-8'
    7     5        INIT_FCALL                                               'max'
          6        INIT_FCALL                                               'mb_strlen'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $12     
         10        SEND_VAR                                                 $12
         11        INIT_FCALL                                               'mb_strlen'
         12        SEND_VAR                                                 !1
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                         $13     
         15        SEND_VAR                                                 $13
         16        DO_ICALL                                         $14     
         17        ASSIGN                                                   !4, $14
    8    18        ASSIGN                                                   !5, 0
         19      > JMP                                                      ->53
    9    20    >   INIT_FCALL                                               'mb_substr'
         21        SEND_VAR                                                 !0
         22        SEND_VAR                                                 !5
         23        SEND_VAL                                                 1
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                         $17     
         26        ASSIGN                                                   !6, $17
   10    27        INIT_FCALL                                               'mb_substr'
         28        SEND_VAR                                                 !1
         29        SEND_VAR                                                 !5
         30        SEND_VAL                                                 1
         31        SEND_VAR                                                 !3
         32        DO_ICALL                                         $19     
         33        ASSIGN                                                   !7, $19
   11    34        IS_IDENTICAL                                             !6, !7
         35      > JMPZ                                                     ~21, ->37
         36    > > JMP                                                      ->52
   13    37    >   INIT_FCALL                                               'array_search'
         38        SEND_VAR                                                 !6
         39        SEND_VAR                                                 !2
         40        DO_ICALL                                         $22     
         41        ASSIGN                                                   !8, $22
   14    42        INIT_FCALL                                               'array_search'
         43        SEND_VAR                                                 !7
         44        SEND_VAR                                                 !2
         45        DO_ICALL                                         $24     
         46        ASSIGN                                                   !9, $24
   15    47        IS_IDENTICAL                                             !8, !9
         48      > JMPZ                                                     ~26, ->50
         49    > > JMP                                                      ->52
   17    50    >   SUB                                              ~27     !8, !9
         51      > RETURN                                                   ~27
    8    52    >   PRE_INC                                                  !5
         53    >   IS_SMALLER                                               !5, !4
         54      > JMPNZ                                                    ~29, ->20
   19    55    > > RETURN                                                   0
   20    56*     > RETURN                                                   null

End of function alphabetize_custom

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.02 ms | 1400 KiB | 25 Q