3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Here is your sorting order: $sorts = [ 'Manager' => 1, 'Assistant' => 2, 'Flexworker' => 3, 'Cleaning' => 4, 'Frontoffice' => 5, 'Other' => 6 ]; // This is representative data: $employees = [ ['name' => 'Jan', 'category' => 'Cleaning'], ['name' => 'Jane', 'category' => 'Manager'], ['name' => 'Jano', 'category' => 'Assistant'], ['name' => 'Janu', 'category' => 'Assistant'], ['name' => 'Janx', 'category' => 'Flexworker'], ['name' => 'Janny', 'category' => 'Frontoffice'], ['name' => 'Jando', 'category' => 'Other'], ['name' => 'Jansan', 'category' => 'Manager'], ]; // Here we lookup the sorting value for each category usort($employees, function($a, $b) use ($sorts) { return $sorts[$a['category']] <=> $sorts[$b['category']]; }); print_r($employees);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nm55v
function name:  (null)
number of ops:  12
compiled vars:  !0 = $sorts, !1 = $employees
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                       !0, <array>
   16     1        ASSIGN                                                       !1, <array>
   29     2        INIT_FCALL                                                   'usort'
          3        SEND_REF                                                     !1
          4        DECLARE_LAMBDA_FUNCTION                              ~4      [0]
          5        BIND_LEXICAL                                                 ~4, !0
   31     6        SEND_VAL                                                     ~4
   29     7        DO_ICALL                                                     
   33     8        INIT_FCALL                                                   'print_r'
          9        SEND_VAR                                                     !1
         10        DO_ICALL                                                     
         11      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nm55v
function name:  {closure:/in/nm55v:29}
number of ops:  10
compiled vars:  !0 = $a, !1 = $b, !2 = $sorts
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
   30     3        FETCH_DIM_R                                          ~3      !0, 'category'
          4        FETCH_DIM_R                                          ~4      !2, ~3
          5        FETCH_DIM_R                                          ~5      !1, 'category'
          6        FETCH_DIM_R                                          ~6      !2, ~5
          7        SPACESHIP                                            ~7      ~4, ~6
          8      > RETURN                                                       ~7
   31     9*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.83 ms | 2113 KiB | 15 Q