3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sort_me = [ ["file" => "Desert.jpg"], ["file" => "What.jpg"], ["file" => "Hello.jpg"], ["file" => "Test.jpg"], ["file" => "Goodness.jpg"], ]; $sort_order = ["Test.jpg", "Hello.jpg", "NotFound.jpg"]; $lookup = array_flip($sort_order); $fallback = count($sort_order); usort($sort_me, function($a, $b) use ($lookup, $fallback) { return [$lookup[$a['file']] ?? $fallback, $a['file']] <=> [$lookup[$b['file']] ?? $fallback, $b['file']]; }); var_export($sort_me);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YpktO
function name:  (null)
number of ops:  19
compiled vars:  !0 = $sort_me, !1 = $sort_order, !2 = $lookup, !3 = $fallback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   12     2        INIT_FCALL                                               'array_flip'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !2, $6
   13     6        COUNT                                            ~8      !1
          7        ASSIGN                                                   !3, ~8
   15     8        INIT_FCALL                                               'usort'
          9        SEND_REF                                                 !0
         10        DECLARE_LAMBDA_FUNCTION                          ~10     [0]
         11        BIND_LEXICAL                                             ~10, !2
         12        BIND_LEXICAL                                             ~10, !3
   19    13        SEND_VAL                                                 ~10
   15    14        DO_ICALL                                                 
   21    15        INIT_FCALL                                               'var_export'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                                 
         18      > 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/YpktO
function name:  {closure}
number of ops:  21
compiled vars:  !0 = $a, !1 = $b, !2 = $lookup, !3 = $fallback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
   16     4        FETCH_DIM_R                                      ~4      !0, 'file'
          5        FETCH_DIM_IS                                     ~5      !2, ~4
          6        COALESCE                                         ~6      ~5
          7        QM_ASSIGN                                        ~6      !3
          8        INIT_ARRAY                                       ~7      ~6
          9        FETCH_DIM_R                                      ~8      !0, 'file'
         10        ADD_ARRAY_ELEMENT                                ~7      ~8
   18    11        FETCH_DIM_R                                      ~9      !1, 'file'
         12        FETCH_DIM_IS                                     ~10     !2, ~9
         13        COALESCE                                         ~11     ~10
         14        QM_ASSIGN                                        ~11     !3
         15        INIT_ARRAY                                       ~12     ~11
         16        FETCH_DIM_R                                      ~13     !1, 'file'
         17        ADD_ARRAY_ELEMENT                                ~12     ~13
         18        SPACESHIP                                        ~14     ~7, ~12
         19      > RETURN                                                   ~14
   19    20*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.2 ms | 1009 KiB | 16 Q