3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ ['id' => 7867867, 'title' => 'Some Title'], ['id' => 3452342, 'title' => 'Some Title'], ['id' => 'foo', 'title' => 'Some Title'], ['id' => 1231233, 'title' => 'Some Title'], ['id' => 'bar', 'title' => 'Some Title'], ['id' => 5867867, 'title' => 'Some Title'] ]; // restructure with values as keys, and keys as order (ASC) $order = array_flip([3452342, 5867867, 7867867, 1231233]); // generating $order = [3452342 => 0, 5867867 => 1, 7867867 => 2, 1231233 => 3]; $default = count($order); // generating $default = 4 usort($array, function($a, $b) use($order, $default) { return ($order[$a['id']] ?? $default) <=> ($order[$b['id']] ?? $default); }); var_export($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MaKkb
function name:  (null)
number of ops:  18
compiled vars:  !0 = $array, !1 = $order, !2 = $default
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   13     1        INIT_FCALL                                                   'array_flip'
          2        SEND_VAL                                                     <array>
          3        DO_ICALL                                             $4      
          4        ASSIGN                                                       !1, $4
   16     5        COUNT                                                ~6      !1
          6        ASSIGN                                                       !2, ~6
   20     7        INIT_FCALL                                                   'usort'
          8        SEND_REF                                                     !0
          9        DECLARE_LAMBDA_FUNCTION                              ~8      [0]
         10        BIND_LEXICAL                                                 ~8, !1
         11        BIND_LEXICAL                                                 ~8, !2
   22    12        SEND_VAL                                                     ~8
   20    13        DO_ICALL                                                     
   24    14        INIT_FCALL                                                   'var_export'
         15        SEND_VAR                                                     !0
         16        DO_ICALL                                                     
         17      > 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/MaKkb
function name:  {closure:/in/MaKkb:20}
number of ops:  15
compiled vars:  !0 = $a, !1 = $b, !2 = $order, !3 = $default
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
          3        BIND_STATIC                                                  !3
   21     4        FETCH_DIM_R                                          ~4      !0, 'id'
          5        FETCH_DIM_IS                                         ~5      !2, ~4
          6        COALESCE                                             ~6      ~5
          7        QM_ASSIGN                                            ~6      !3
          8        FETCH_DIM_R                                          ~7      !1, 'id'
          9        FETCH_DIM_IS                                         ~8      !2, ~7
         10        COALESCE                                             ~9      ~8
         11        QM_ASSIGN                                            ~9      !3
         12        SPACESHIP                                            ~10     ~6, ~9
         13      > RETURN                                                       ~10
   22    14*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
176.7 ms | 2238 KiB | 16 Q