3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [], ['2011','2010', '2012'], ['conference', 'journal', 'conference'], ]; function array_multisort_custom(array &$array, $columnKey, array $order) { // guard clause/condition if (!array_key_exists($columnKey, $array)) { throw new Exception('Nominated sorting column not found'); } // pad rows to consistent size $maxCount = max(array_map('count', $array)); array_walk($array, fn(&$row) => $row = array_pad($row, $maxCount, null)); // populate first sorting parameter with custom order array $priority = array_flip($order); $default = count($order); array_multisort( array_map(fn($v) => $priority[$v] ?? $default, $array[$columnKey]), ...$array ); } array_multisort_custom($array, 2, ['conference', 'journal']); var_export($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3Md9Z
function name:  (null)
number of ops:  10
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   30     1        INIT_FCALL                                               'array_multisort_custom'
          2        SEND_REF                                                 !0
          3        SEND_VAL                                                 2
          4        SEND_VAL                                                 <array>
          5        DO_FCALL                                      0          
   31     6        INIT_FCALL                                               'var_export'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function array_multisort_custom:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3Md9Z
function name:  array_multisort_custom
number of ops:  44
compiled vars:  !0 = $array, !1 = $columnKey, !2 = $order, !3 = $maxCount, !4 = $priority, !5 = $default
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   12     3        ARRAY_KEY_EXISTS                                 ~6      !1, !0
          4        BOOL_NOT                                         ~7      ~6
          5      > JMPZ                                                     ~7, ->10
   13     6    >   NEW                                              $8      'Exception'
          7        SEND_VAL_EX                                              'Nominated+sorting+column+not+found'
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $8
   17    10    >   INIT_FCALL                                               'max'
         11        INIT_FCALL                                               'array_map'
         12        SEND_VAL                                                 'count'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $10     
         15        SEND_VAR                                                 $10
         16        DO_ICALL                                         $11     
         17        ASSIGN                                                   !3, $11
   18    18        INIT_FCALL                                               'array_walk'
         19        SEND_REF                                                 !0
         20        DECLARE_LAMBDA_FUNCTION                          ~13     [0]
         21        BIND_LEXICAL                                             ~13, !3
         22        SEND_VAL                                                 ~13
         23        DO_ICALL                                                 
   21    24        INIT_FCALL                                               'array_flip'
         25        SEND_VAR                                                 !2
         26        DO_ICALL                                         $15     
         27        ASSIGN                                                   !4, $15
   22    28        COUNT                                            ~17     !2
         29        ASSIGN                                                   !5, ~17
   24    30        INIT_FCALL                                               'array_multisort'
   25    31        INIT_FCALL                                               'array_map'
         32        DECLARE_LAMBDA_FUNCTION                          ~19     [1]
         33        BIND_LEXICAL                                             ~19, !4
         34        BIND_LEXICAL                                             ~19, !5
         35        SEND_VAL                                                 ~19
         36        FETCH_DIM_R                                      ~20     !0, !1
         37        SEND_VAL                                                 ~20
         38        DO_ICALL                                         $21     
         39        SEND_VAL                                                 $21
   26    40        SEND_UNPACK                                              !0
         41        CHECK_UNDEF_ARGS                                         
   24    42        DO_ICALL                                                 
   28    43      > 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/3Md9Z
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $row, !1 = $maxCount
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_FCALL                                               'array_pad'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 null
          6        DO_ICALL                                         $2      
          7        ASSIGN                                           ~3      !0, $2
          8      > RETURN                                                   ~3
          9*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3Md9Z
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $v, !1 = $priority, !2 = $default
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
          3        FETCH_DIM_IS                                     ~3      !1, !0
          4        COALESCE                                         ~4      ~3
          5        QM_ASSIGN                                        ~4      !2
          6      > RETURN                                                   ~4
          7*     > RETURN                                                   null

End of Dynamic Function 1

End of function array_multisort_custom

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.55 ms | 1440 KiB | 21 Q