3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ 'note' => [], 'year' => ['2011','2010', '2012'], 'type' => ['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); foreach ($array[$columnKey] as $v) { $params[0][] = $priority[$v] ?? $default; } // assign reference variables to parameter array for all rows foreach ($array as &$row) { $params[] = &$row; } array_multisort(...$params); } array_multisort_custom($array, 'type', ['conference', 'journal']); var_export($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RUVqc
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>
   35     1        INIT_FCALL                                                   'array_multisort_custom'
          2        SEND_REF                                                     !0
          3        SEND_VAL                                                     'type'
          4        SEND_VAL                                                     <array>
          5        DO_FCALL                                          0          
   36     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
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 40
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 40
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 40
2 jumps found. (Code = 125) Position 1 = 42, Position 2 = 46
Branch analysis from position: 42
2 jumps found. (Code = 126) Position 1 = 43, Position 2 = 46
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
Branch analysis from position: 40
filename:       /in/RUVqc
function name:  array_multisort_custom
number of ops:  52
compiled vars:  !0 = $array, !1 = $columnKey, !2 = $order, !3 = $maxCount, !4 = $priority, !5 = $default, !6 = $v, !7 = $params, !8 = $row
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                                     ~9      !1, !0
          4        BOOL_NOT                                             ~10     ~9
          5      > JMPZ                                                         ~10, ->10
   13     6    >   NEW                                                  $11     'Exception'
          7        SEND_VAL_EX                                                  'Nominated+sorting+column+not+found'
          8        DO_FCALL                                          0          
          9      > THROW                                             0          $11
   17    10    >   INIT_FCALL                                                   'max'
         11        INIT_FCALL                                                   'array_map'
         12        SEND_VAL                                                     'count'
         13        SEND_VAR                                                     !0
         14        DO_ICALL                                             $13     
         15        SEND_VAR                                                     $13
         16        DO_ICALL                                             $14     
         17        ASSIGN                                                       !3, $14
   18    18        INIT_FCALL                                                   'array_walk'
         19        SEND_REF                                                     !0
         20        DECLARE_LAMBDA_FUNCTION                              ~16     [0]
         21        BIND_LEXICAL                                                 ~16, !3
         22        SEND_VAL                                                     ~16
         23        DO_ICALL                                                     
   21    24        INIT_FCALL                                                   'array_flip'
         25        SEND_VAR                                                     !2
         26        DO_ICALL                                             $18     
         27        ASSIGN                                                       !4, $18
   22    28        COUNT                                                ~20     !2
         29        ASSIGN                                                       !5, ~20
   23    30        FETCH_DIM_R                                          ~22     !0, !1
         31      > FE_RESET_R                                           $23     ~22, ->40
         32    > > FE_FETCH_R                                                   $23, !6, ->40
   24    33    >   FETCH_DIM_IS                                         ~26     !4, !6
         34        COALESCE                                             ~27     ~26
         35        QM_ASSIGN                                            ~27     !5
         36        FETCH_DIM_W                                          $24     !7, 0
         37        ASSIGN_DIM                                                   $24
         38        OP_DATA                                                      ~27
   23    39      > JMP                                                          ->32
         40    >   FE_FREE                                                      $23
   28    41      > FE_RESET_RW                                          $28     !0, ->46
         42    > > FE_FETCH_RW                                                  $28, !8, ->46
   29    43    >   FETCH_DIM_W                                          $29     !7
         44        ASSIGN_REF                                                   $29, !8
   28    45      > JMP                                                          ->42
         46    >   FE_FREE                                                      $28
   32    47        INIT_FCALL                                                   'array_multisort'
         48        SEND_UNPACK                                                  !7
         49        CHECK_UNDEF_ARGS                                             
         50        DO_ICALL                                                     
   33    51      > 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/RUVqc
function name:  {closure:array_multisort_custom():18}
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

End of function array_multisort_custom

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.47 ms | 1768 KiB | 21 Q