3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ (object)['id' => 8], (object)['id' => 7], (object)['id' => 5] ]; $order = [5, 8, 1]; $order = array_flip($order); $order[''] = max(array_column($array, 'id')) + 1; usort($array, function($a, $b) use ($order) { return ($order[$a->id] ?? $order['']) <=> ($order[$b->id] ?? $order['']); }); var_export($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LsI37
function name:  (null)
number of ops:  32
compiled vars:  !0 = $array, !1 = $order
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   CAST                                              8  ~2      <array>
          1        INIT_ARRAY                                           ~3      ~2
          2        CAST                                              8  ~4      <array>
          3        ADD_ARRAY_ELEMENT                                    ~3      ~4
          4        CAST                                              8  ~5      <array>
          5        ADD_ARRAY_ELEMENT                                    ~3      ~5
    2     6        ASSIGN                                                       !0, ~3
    8     7        ASSIGN                                                       !1, <array>
   10     8        INIT_FCALL                                                   'array_flip'
          9        SEND_VAR                                                     !1
         10        DO_ICALL                                             $8      
         11        ASSIGN                                                       !1, $8
   11    12        INIT_FCALL                                                   'max'
         13        INIT_FCALL                                                   'array_column'
         14        SEND_VAR                                                     !0
         15        SEND_VAL                                                     'id'
         16        DO_ICALL                                             $11     
         17        SEND_VAR                                                     $11
         18        DO_ICALL                                             $12     
         19        ADD                                                  ~13     $12, 1
         20        ASSIGN_DIM                                                   !1, ''
         21        OP_DATA                                                      ~13
   13    22        INIT_FCALL                                                   'usort'
         23        SEND_REF                                                     !0
         24        DECLARE_LAMBDA_FUNCTION                              ~14     [0]
         25        BIND_LEXICAL                                                 ~14, !1
   15    26        SEND_VAL                                                     ~14
   13    27        DO_ICALL                                                     
   16    28        INIT_FCALL                                                   'var_export'
         29        SEND_VAR                                                     !0
         30        DO_ICALL                                                     
         31      > 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/LsI37
function name:  {closure:/in/LsI37:13}
number of ops:  16
compiled vars:  !0 = $a, !1 = $b, !2 = $order
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
   14     3        FETCH_OBJ_R                                          ~3      !0, 'id'
          4        FETCH_DIM_IS                                         ~4      !2, ~3
          5        COALESCE                                             ~5      ~4
          6        FETCH_DIM_R                                          ~6      !2, ''
          7        QM_ASSIGN                                            ~5      ~6
          8        FETCH_OBJ_R                                          ~7      !1, 'id'
          9        FETCH_DIM_IS                                         ~8      !2, ~7
         10        COALESCE                                             ~9      ~8
         11        FETCH_DIM_R                                          ~10     !2, ''
         12        QM_ASSIGN                                            ~9      ~10
         13        SPACESHIP                                            ~11     ~5, ~9
         14      > RETURN                                                       ~11
   15    15*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
174.55 ms | 2125 KiB | 18 Q