3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ ['type' => 'F'], ['type' => 'C'], ['Bar'], ['type' => 'B'], ['type' => 'H'], ['type' => 'D'], ['Foo'], ['type' => 'D'], ['A', 'B', 'C'], ['type' => 'F'], ['type' => 'Foo'], ['type' => 'Bar'], ['type' => 'A'], ['type' => 'E'], ['type' => 'Bar'], ]; $priorities = [ 'A' => 8, 'B' => 7, 'C' => 6, 'D' => 5, 'E' => 4, 'F' => 3, 'G' => 2, 'H' => 1, ]; function arraySortPriority(array &$array, $column, array $priorities):void { usort($array, function($a, $b) use ($column, $priorities) { $aFocus = $a[$column] ?? null; $bFocus = $b[$column] ?? null; return [array_key_exists($column, $b), $priorities[$bFocus] ?? 0, $aFocus] <=> [array_key_exists($column, $a), $priorities[$aFocus] ?? 0, $bFocus]; }); } arraySortPriority($array, 'type', $priorities); var_export($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YWSAG
function name:  (null)
number of ops:  11
compiled vars:  !0 = $array, !1 = $priorities
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   21     1        ASSIGN                                                       !1, <array>
   43     2        INIT_FCALL                                                   'arraysortpriority'
          3        SEND_REF                                                     !0
          4        SEND_VAL                                                     'type'
          5        SEND_VAR                                                     !1
          6        DO_FCALL                                          0          
   45     7        INIT_FCALL                                                   'var_export'
          8        SEND_VAR                                                     !0
          9        DO_ICALL                                                     
         10      > RETURN                                                       1

Function arraysortpriority:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YWSAG
function name:  arraySortPriority
number of ops:  11
compiled vars:  !0 = $array, !1 = $column, !2 = $priorities
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   32     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   34     3        INIT_FCALL                                                   'usort'
          4        SEND_REF                                                     !0
          5        DECLARE_LAMBDA_FUNCTION                              ~3      [0]
          6        BIND_LEXICAL                                                 ~3, !1
          7        BIND_LEXICAL                                                 ~3, !2
   40     8        SEND_VAL                                                     ~3
   34     9        DO_ICALL                                                     
   41    10      > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YWSAG
function name:  {closure:arraySortPriority():34}
number of ops:  29
compiled vars:  !0 = $a, !1 = $b, !2 = $column, !3 = $priorities, !4 = $aFocus, !5 = $bFocus
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   34     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
          3        BIND_STATIC                                                  !3
   35     4        FETCH_DIM_IS                                         ~6      !0, !2
          5        COALESCE                                             ~7      ~6
          6        QM_ASSIGN                                            ~7      null
          7        ASSIGN                                                       !4, ~7
   36     8        FETCH_DIM_IS                                         ~9      !1, !2
          9        COALESCE                                             ~10     ~9
         10        QM_ASSIGN                                            ~10     null
         11        ASSIGN                                                       !5, ~10
   37    12        ARRAY_KEY_EXISTS                                     ~12     !2, !1
         13        INIT_ARRAY                                           ~13     ~12
         14        FETCH_DIM_IS                                         ~14     !3, !5
         15        COALESCE                                             ~15     ~14
         16        QM_ASSIGN                                            ~15     0
         17        ADD_ARRAY_ELEMENT                                    ~13     ~15
         18        ADD_ARRAY_ELEMENT                                    ~13     !4
   39    19        ARRAY_KEY_EXISTS                                     ~16     !2, !0
         20        INIT_ARRAY                                           ~17     ~16
         21        FETCH_DIM_IS                                         ~18     !3, !4
         22        COALESCE                                             ~19     ~18
         23        QM_ASSIGN                                            ~19     0
         24        ADD_ARRAY_ELEMENT                                    ~17     ~19
         25        ADD_ARRAY_ELEMENT                                    ~17     !5
         26        SPACESHIP                                            ~20     ~13, ~17
         27      > RETURN                                                       ~20
   40    28*     > RETURN                                                       null

End of Dynamic Function 0

End of function arraysortpriority

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
168.43 ms | 2296 KiB | 16 Q